Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eaa0144

Browse files
committedJan 29, 2016
Improve Yard documentation
1 parent a68e835 commit eaa0144

14 files changed

+77
-1
lines changed
 

‎Fudgefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ task_group :spec do
33
end
44

55
task_group :docs do
6-
task :yard, :coverage => 68
6+
task :yard, :coverage => 100
77
end
88

99
task_group :codestyle do

‎lib/sageone_sdk.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module SageoneSdk
66
class << self
77
include SageoneSdk::Configurable
88

9+
# Returns an instance of SageoneSdk::Client
910
def client
1011
@client = SageoneSdk::Client.new unless defined?(@client)
1112
@client

‎lib/sageone_sdk/client.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,59 @@ def initialize(options = {})
6262
end
6363
end
6464

65+
# Last Response
6566
def last_response
6667
@last_response if defined? @last_response
6768
end
6869

70+
# Paginate Get Request
71+
# @param [String] resource the request resource
72+
# @param [Hash] options the request data
6973
def paginate(resource, options = {})
7074
data = get(resource, options)
7175
data
7276
end
7377

78+
# Get Request
79+
# @param [String] path the request path
80+
# @param [Hash] data the request data
7481
def get(path, data={})
7582
request(:get, path, data)
7683
end
7784

85+
# Post Request
86+
# @param [String] path the request path
87+
# @param [Hash] data the request data
7888
def post(path, data={})
7989
request(:post, path, data)
8090
end
8191

92+
# Put Request
93+
# @param [String] path the request path
94+
# @param [Hash] data the request data
8295
def put(path, data={})
8396
request(:put, path, data)
8497
end
8598

99+
# Delete Request
100+
# @param [String] path the request path
101+
# @param [Hash] data the request data
86102
def delete(path, data={})
87103
request(:delete, path, data)
88104
end
89105

106+
# Request
107+
# @param [String] method the request method
108+
# @param [String] path the request path
109+
# @param [Hash] data the request data
110+
# @param [Hash] options Options for the request
90111
def request(method, path, data, options = {})
91112
path = File.join("accounts", "v1", path)
92113
@last_response = response = agent.public_send(method, URI::Parser.new.escape(path.to_s), data, options)
93114
response.body
94115
end
95116

117+
# Agent
96118
def agent
97119
@agent ||= Faraday.new(api_endpoint, faraday_options) do |builder|
98120
builder.request :url_encoded

‎lib/sageone_sdk/client/contact_types.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ class Client
33

44
# Represents the types of contact records in Sage One such as Customer or Supplier.
55
module ContactTypes
6+
# Customer Contact Type
67
CUSTOMER = 1.freeze
8+
# Supplier Contact Type
79
SUPPLIER = 2.freeze
810

911
# @return [object] Returns all of the contact types in Sage One. For example, Customer.

‎lib/sageone_sdk/client/expenditures.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@ module SageoneSdk
22
class Client
33
# Expenditures
44
module Expenditures
5+
# @return [object] Returns paginated expenditures for the authenticated user's business.
56
def expenditures(options = {})
67
paginate "expenditures", options
78
end
89

10+
# @return [object] Returns the expenditure with the given id.
911
def expenditure(id, options = {})
1012
get "expenditures/#{id}", options
1113
end
1214

15+
# Creates an expenditure with the data provided
16+
# @param [hash] data The expenditure information
17+
# @param [hash] options
1318
def create_expenditure(data, options = {})
1419
post "expenditures", :expenditure => data
1520
end
1621

22+
# Updates an expenditure with the data provided
23+
# @param [integer] id The expenditure id
24+
# @param [hash] data The expenditure information
25+
# @param [hash] options
1726
def update_expenditure(id, data, options = {})
1827
put "expenditures/#{id}", :expenditure => data
1928
end
2029

30+
# Deletes the specified expenditure
31+
# @param [integer] id The expenditure id
32+
# @param [hash] options
2133
def delete_expenditure(id, options = {})
2234
delete "expenditures/#{id}"
2335
end

‎lib/sageone_sdk/configurable.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Configurable
66
attr_writer :api_endpoint
77

88
class << self
9+
# Configuration Keys
910
def keys
1011
@keys ||= [
1112
:access_token,
@@ -18,10 +19,12 @@ def keys
1819
end
1920
end
2021

22+
# Configure
2123
def configure
2224
yield self
2325
end
2426

27+
# Reset!
2528
def reset!
2629
SageoneSdk::Configurable.keys.each do |key|
2730
instance_variable_set(:"@#{key}", SageoneSdk::Default.options[key])
@@ -30,6 +33,7 @@ def reset!
3033
end
3134
alias :setup :reset!
3235

36+
# Api Endpoint
3337
def api_endpoint
3438
File.join(@api_endpoint, "")
3539
end

‎lib/sageone_sdk/default.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,49 @@
33
module SageoneSdk
44
# Default
55
module Default
6+
# Default Access Token
67
ACCESS_TOKEN = "default_access_token"
8+
# Default Signing Secret
79
SIGNING_SECRET = "default_signing_secret"
10+
# API Endpoint
811
API_ENDPOINT = "https://api.sageone.com".freeze
12+
# User Agent
913
USER_AGENT = "sageone_sdk Ruby Gem #{SageoneSdk::VERSION}".freeze
14+
# Media Type
1015
MEDIA_TYPE = "application/json"
1116

1217
class << self
18+
# Options
1319
def options
1420
Hash[SageoneSdk::Configurable.keys.map{|key| [key, send(key)]}]
1521
end
1622

23+
# Retrieve access token
1724
def access_token
1825
ENV["SAGE_ONE_ACCESS_TOKEN"] || ACCESS_TOKEN
1926
end
2027

28+
# Retrieve signing secret
2129
def signing_secret
2230
ENV["SAGE_ONE_SIGNING_SECRET"] || SIGNING_SECRET
2331
end
2432

33+
# Retrieve api endpoint
2534
def api_endpoint
2635
ENV["SAGE_ONE_API_ENDPOINT"] || API_ENDPOINT
2736
end
2837

38+
# Retrieve media type
2939
def default_media_type
3040
ENV["SAGE_ONE_DEFAULT_MEDIA_TYPE"] || MEDIA_TYPE
3141
end
3242

43+
# Retrieve user agent
3344
def user_agent
3445
ENV["SAGE_ONE_USER_AGENT"] || USER_AGENT
3546
end
3647

48+
# Connection Options
3749
def connection_options
3850
{
3951
:headers => {

‎lib/sageone_sdk/middleware.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module SageoneSdk
2+
# Middleware
23
module Middleware
34
autoload :Signature, "sageone_sdk/middleware/signature"
45
autoload :SDataParser, "sageone_sdk/middleware/sdata_parser"

‎lib/sageone_sdk/middleware/sdata_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module SageoneSdk
88
module Middleware
99
# Sdata parser
1010
class SDataParser < Faraday::Middleware
11+
# Call
1112
def call(environment)
1213
@app.call(environment).on_complete do |env|
1314
element = ::JSON.parse(env[:body])

‎lib/sageone_sdk/middleware/signature.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def initialize(app, access_token, signing_secret)
1212
@signing_secret = signing_secret
1313
end
1414

15+
# Call
1516
def call(env)
1617
nonce = SageoneSdk::Signature.generate_nonce
1718
signature = SageoneSdk::Signature.new(env.method, env.url, env.body, nonce, @signing_secret, @access_token)

‎lib/sageone_sdk/sdata_error_response.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,31 @@ def initialize(data = {})
77
@data = data
88
end
99

10+
# Diagnoses
1011
def diagnoses
1112
@data["$diagnoses"]
1213
end
1314

15+
# Full Messages
1416
def full_messages
1517
diagnoses.map do |x|
1618
"#{x["$source"].humanize}: #{x["$message"]}"
1719
end
1820
end
1921

22+
# Error?
23+
# @return Boolean
2024
def error?
2125
true
2226
end
2327

28+
# Respond to missing?
29+
# @return Boolean
2430
def respond_to_missing?(method, include_private = false)
2531
resources.respond_to?(method, include_private)
2632
end
2733

34+
# Handle method missing
2835
def method_missing(method, *args, &block)
2936
if diagnoses.respond_to?(method)
3037
diagnoses.send(method, *args)

‎lib/sageone_sdk/sdata_response.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@ def initialize(data = {})
77
@data = data
88
end
99

10+
# Total Results
1011
def total_results
1112
@data["$totalResults"]
1213
end
1314

15+
# Starting Index
1416
def start_index
1517
@data["startIndex"]
1618
end
1719

20+
# Items Per Page
1821
def items_per_page
1922
@data["$itemsPerPage"]
2023
end
2124

25+
# Resources
2226
def resources
2327
@data["$resources"]
2428
end
2529

30+
# Error?
31+
# @return Boolean
2632
def error?
2733
false
2834
end
2935

36+
# Find By
37+
# @param conditions
3038
def find_by(conditions)
3139
resources.detect do |resource|
3240
@skip = false
@@ -41,10 +49,13 @@ def find_by(conditions)
4149
end
4250
end
4351

52+
# Respond to missing?
53+
# @return Boolean
4454
def respond_to_missing?(method, include_private = false)
4555
resources.respond_to?(method, include_private) || data.respond_to?(method, include_private)
4656
end
4757

58+
# Handle method missing
4859
def method_missing(method, *args, &block)
4960
if resources.respond_to?(method)
5061
resources.send(method, *args)

‎lib/sageone_sdk/signature.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def initialize(http_method, url, request_body, nonce, secret, token)
1717
@token = token
1818
end
1919

20+
# Generate None
2021
def self.generate_nonce
2122
SecureRandom.hex
2223
end

‎lib/sageone_sdk/version.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module SageoneSdk
2+
# Version Number
23
VERSION = "0.0.1"
34
end

0 commit comments

Comments
 (0)
Please sign in to comment.