myob-api 0.3 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/myob/api/models/base.rb +43 -9
- data/lib/myob/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8df0abcdeb32b2e03172cdd5ab88157f11d05885
|
4
|
+
data.tar.gz: 438f9ad29d1121dd988230b511bfe583fab71916
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50264fb983d752d308b22906dd8cb6687eb206a2e6851764cdbbb5c63c747c8d7f99548cd1cb02893f16f94b845ec674a8766ba58a3c4fdb376d00efee50f4bd
|
7
|
+
data.tar.gz: e8f920988346d2d0038b3462bdeabfd060a3d46c1f235d33e8c2a71fa61b664a75126d03504c16f830ddb26012b27b088223fa21f1d0f25147bade06bde16e11
|
data/README.md
CHANGED
@@ -126,6 +126,23 @@ Return a list of all invoices
|
|
126
126
|
|
127
127
|
api_client.invoice.all
|
128
128
|
|
129
|
+
#### Pagination
|
130
|
+
|
131
|
+
Basic pagination based on `NextPageLink` parameter returned via [API](http://developer.myob.com/api/accountright/api-overview/retrieving-data/)
|
132
|
+
|
133
|
+
first_page = api_client.contact.all
|
134
|
+
second_page = api_client.contact.next_page if api_client.contact.next_page?
|
135
|
+
|
136
|
+
You can also get an array of all items (which may make several API calls in the background):
|
137
|
+
|
138
|
+
api_client.contact.all_items # note this returns an array, *not* a hash the way `api_client.contact.all` does
|
139
|
+
|
140
|
+
#### Fetching one entity
|
141
|
+
|
142
|
+
Return an entity with given `UID`:
|
143
|
+
|
144
|
+
contact = api_client.contact.find(contact_uid)
|
145
|
+
|
129
146
|
#### Creating an entity
|
130
147
|
|
131
148
|
To create a new entity, call #save on its model, passing through a hash that represents the entity. Refer to the MYOB API documentation for required fields.
|
data/lib/myob/api/models/base.rb
CHANGED
@@ -6,8 +6,9 @@ module Myob
|
|
6
6
|
API_URL = 'https://api.myob.com/accountright/'
|
7
7
|
|
8
8
|
def initialize(client, model_name)
|
9
|
-
@client
|
10
|
-
@model_name
|
9
|
+
@client = client
|
10
|
+
@model_name = model_name || 'Base'
|
11
|
+
@next_page_link = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
def model_route
|
@@ -15,18 +16,34 @@ module Myob
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def all(query = nil)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
perform_request(self.url, query)
|
20
|
+
end
|
21
|
+
|
22
|
+
def next_page?
|
23
|
+
!!@next_page_link
|
24
|
+
end
|
25
|
+
|
26
|
+
def next_page(query = nil)
|
27
|
+
perform_request(@next_page_link, query)
|
28
|
+
end
|
29
|
+
|
30
|
+
def all_items(query = nil)
|
31
|
+
results = all(query)["Items"]
|
32
|
+
while next_page?
|
33
|
+
results += next_page(query)["Items"] || []
|
23
34
|
end
|
35
|
+
results
|
24
36
|
end
|
25
37
|
|
26
38
|
def get(query = nil)
|
27
39
|
all(query)
|
28
40
|
end
|
29
|
-
|
41
|
+
|
42
|
+
def find(id)
|
43
|
+
object = { 'UID' => id }
|
44
|
+
perform_request(self.url(object))
|
45
|
+
end
|
46
|
+
|
30
47
|
def first(query = nil)
|
31
48
|
model_data = self.all(query)
|
32
49
|
model_data[0] if model_data.length > 0
|
@@ -43,8 +60,10 @@ module Myob
|
|
43
60
|
def url(object = nil)
|
44
61
|
if self.model_route == ''
|
45
62
|
"#{API_URL}"
|
63
|
+
elsif object && object['UID']
|
64
|
+
"#{resource_url}/#{object['UID']}"
|
46
65
|
else
|
47
|
-
|
66
|
+
resource_url
|
48
67
|
end
|
49
68
|
end
|
50
69
|
|
@@ -78,6 +97,21 @@ module Myob
|
|
78
97
|
def date_formatter
|
79
98
|
"%Y-%m-%dT%H:%M:%S"
|
80
99
|
end
|
100
|
+
|
101
|
+
def resource_url
|
102
|
+
"#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}"
|
103
|
+
end
|
104
|
+
|
105
|
+
def perform_request(url, query = nil)
|
106
|
+
model_data = parse_response(@client.connection.get(url, {:headers => @client.headers}))
|
107
|
+
@next_page_link = model_data['NextPageLink'] if self.model_route != ''
|
108
|
+
|
109
|
+
if query
|
110
|
+
process_query(model_data, query)
|
111
|
+
else
|
112
|
+
model_data
|
113
|
+
end
|
114
|
+
end
|
81
115
|
|
82
116
|
def parse_response(response)
|
83
117
|
JSON.parse(response.body)
|
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.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Lumley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|