myob-api 0.9.5 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/myob-api.rb +1 -0
- data/lib/myob/api/client.rb +31 -9
- data/lib/myob/api/models/base.rb +12 -4
- data/lib/myob/api/models/customer_payment.rb +11 -0
- data/lib/myob/api/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5e048f96fb5846bce047fe559ef780bbad33602
|
4
|
+
data.tar.gz: ef9f5324aaf724ccf29f85fe865bec18bbfe4ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35941ab08da89b63a24c8ec10d04c3c76e007e6c2c12860d16343e80a38adcce7026f0e426a76bf8ddb804bd6c7a695d0fe106e5a6d1c0d19fb75e2de4d9d116
|
7
|
+
data.tar.gz: 1ceee23871eadc95c7a9223f30fa24027d31733c7b61f1f247f2c49c9a49ced7f515e41750f399a502c0b586c27a2ffb587ff7a7597839eb25d15d7f1c333706
|
data/README.md
CHANGED
@@ -84,6 +84,8 @@ Or if you know which Company File you want to access too:
|
|
84
84
|
},
|
85
85
|
})
|
86
86
|
|
87
|
+
If you provide a company file, the gem will attempt to connect to MYOB to get the base API subdomain to use for future requests ([learn more](http://developer.myob.com/api/accountright/best-practice-guides/hypermedia-and-uris/)).
|
88
|
+
|
87
89
|
### API Methods
|
88
90
|
|
89
91
|
#### Company Files
|
data/lib/myob-api.rb
CHANGED
data/lib/myob/api/client.rb
CHANGED
@@ -6,7 +6,7 @@ module Myob
|
|
6
6
|
class Client
|
7
7
|
include Myob::Api::Helpers
|
8
8
|
|
9
|
-
attr_reader :current_company_file, :client
|
9
|
+
attr_reader :current_company_file, :client, :current_company_file_url
|
10
10
|
|
11
11
|
def initialize(options)
|
12
12
|
Myob::Api::Model::Base.subclasses.each {|c| model(c.name.split("::").last)}
|
@@ -15,16 +15,17 @@ module Myob
|
|
15
15
|
@consumer = options[:consumer]
|
16
16
|
@access_token = options[:access_token]
|
17
17
|
@refresh_token = options[:refresh_token]
|
18
|
-
|
18
|
+
|
19
19
|
@client = OAuth2::Client.new(@consumer[:key], @consumer[:secret], {
|
20
20
|
:site => 'https://secure.myob.com',
|
21
21
|
:authorize_url => '/oauth2/account/authorize',
|
22
22
|
:token_url => '/oauth2/v1/authorize',
|
23
23
|
})
|
24
24
|
|
25
|
-
if
|
26
|
-
|
27
|
-
|
25
|
+
# on client init, if we have a company file already, get the appropriate base URL for this company file from MYOB
|
26
|
+
provided_company_file = options[:selected_company_file] || options[:company_file]
|
27
|
+
select_company_file(provided_company_file) if provided_company_file
|
28
|
+
@current_company_file ||= {}
|
28
29
|
end
|
29
30
|
|
30
31
|
def get_access_code_url(params = {})
|
@@ -40,7 +41,7 @@ module Myob
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def headers
|
43
|
-
token = @current_company_file[:token]
|
44
|
+
token = (@current_company_file || {})[:token]
|
44
45
|
if token.nil? || token == ''
|
45
46
|
# if token is blank assume we are using federated login - http://myobapi.tumblr.com/post/109848079164/2015-1-release-notes
|
46
47
|
{
|
@@ -58,18 +59,39 @@ module Myob
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
62
|
+
# given some company file credentials, connect to MYOB and get the appropriate company file object.
|
63
|
+
# store its ID and token for auth'ing requests, and its URL to ensure we talk to the right MYOB server.
|
64
|
+
#
|
65
|
+
# `company_file` should be hash. accepted forms:
|
66
|
+
#
|
67
|
+
# {name: String, username: String, password: String}
|
68
|
+
# {id: String, token: String}
|
61
69
|
def select_company_file(company_file)
|
62
|
-
|
63
|
-
|
70
|
+
# store the provided company file as an ivar so we can use it for subsequent requests
|
71
|
+
# we need the token from it to make the initial request to get company files
|
72
|
+
@current_company_file ||= company_file if company_file[:token]
|
73
|
+
|
74
|
+
selected_company_file = company_files.find {|file|
|
75
|
+
if company_file[:name]
|
76
|
+
file['Name'] == company_file[:name]
|
77
|
+
elsif company_file[:id]
|
78
|
+
file['Id'] == company_file[:id]
|
79
|
+
end
|
80
|
+
}
|
81
|
+
|
82
|
+
if selected_company_file
|
64
83
|
token = company_file[:token]
|
65
84
|
if (token.nil? || token == '') && !company_file[:username].nil? && company_file[:username] != '' && !company_file[:password].nil?
|
66
85
|
# if we have been given login details, encode them into a token
|
67
86
|
token = Base64.encode64("#{company_file[:username]}:#{company_file[:password]}")
|
68
87
|
end
|
69
88
|
@current_company_file = {
|
70
|
-
:id =>
|
89
|
+
:id => selected_company_file['Id'],
|
71
90
|
:token => token
|
72
91
|
}
|
92
|
+
@current_company_file_url = selected_company_file['Uri']
|
93
|
+
else
|
94
|
+
@current_company_file = {}
|
73
95
|
end
|
74
96
|
end
|
75
97
|
|
data/lib/myob/api/models/base.rb
CHANGED
@@ -3,7 +3,7 @@ module Myob
|
|
3
3
|
module Model
|
4
4
|
class Base
|
5
5
|
|
6
|
-
API_URL = 'https://api.myob.com/accountright/'
|
6
|
+
API_URL = 'https://api.myob.com/accountright/' # deprecated except for initial requests - should read from API instead - http://myobapi.tumblr.com/post/141169146113/important-update-accountright-live-cloud-api
|
7
7
|
QUERY_OPTIONS = [:orderby, :top, :skip, :filter]
|
8
8
|
|
9
9
|
def initialize(client, model_name)
|
@@ -61,9 +61,13 @@ module Myob
|
|
61
61
|
|
62
62
|
def url(object = nil, params = nil)
|
63
63
|
url = if self.model_route == ''
|
64
|
-
|
64
|
+
API_URL
|
65
65
|
else
|
66
|
-
|
66
|
+
if @client && @client.current_company_file_url
|
67
|
+
"#{@client.current_company_file_url}/#{self.model_route}#{"/#{object['UID']}" if object && object['UID']}"
|
68
|
+
else
|
69
|
+
"#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}#{"/#{object['UID']}" if object && object['UID']}"
|
70
|
+
end
|
67
71
|
end
|
68
72
|
|
69
73
|
if params.is_a?(Hash)
|
@@ -106,7 +110,11 @@ module Myob
|
|
106
110
|
end
|
107
111
|
|
108
112
|
def resource_url
|
109
|
-
|
113
|
+
if @client && @client.current_company_file_url
|
114
|
+
"#{@client.current_company_file_url}/#{self.model_route}"
|
115
|
+
else
|
116
|
+
"#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}"
|
117
|
+
end
|
110
118
|
end
|
111
119
|
|
112
120
|
def perform_request(url)
|
data/lib/myob/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myob-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Lumley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/myob/api/models/contact.rb
|
75
75
|
- lib/myob/api/models/current_user.rb
|
76
76
|
- lib/myob/api/models/customer.rb
|
77
|
+
- lib/myob/api/models/customer_payment.rb
|
77
78
|
- lib/myob/api/models/employee.rb
|
78
79
|
- lib/myob/api/models/employee_payroll_advice.rb
|
79
80
|
- lib/myob/api/models/employee_payroll_details.rb
|
@@ -107,9 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
108
|
version: '0'
|
108
109
|
requirements: []
|
109
110
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.4.5.1
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
114
|
summary: MYOB AccountRight Live API V2
|
114
115
|
test_files: []
|
115
|
-
has_rdoc:
|