myob-api 0.1.0 → 0.2.0
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 -3
- data/lib/myob/api/client.rb +1 -0
- data/lib/myob/api/models/base.rb +38 -3
- data/lib/myob/api/models/timesheet.rb +16 -0
- 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: df2831ae79d4a7fe595b41d880ae810a3056661e
|
4
|
+
data.tar.gz: a2f14d8e44951ef9299b967eb326d82658a92e23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24bf1a9394ab64e65d8b261d2469af77a97dcdc9648dfe9b38a83e7caa68d053a2eeefc9e5d2751d1263e6c625e7084cbf838d991f287db81fb429a6bb64e896
|
7
|
+
data.tar.gz: f0ed4e36b247ecebf5abdddcfd02d69f70683aa35a3e50002c8c05f94683cbb1216db2b5d1621014e07240b88cdff1d78322d2b0cd78bc8bb8db316cd5695032
|
data/README.md
CHANGED
@@ -86,11 +86,11 @@ Or if you know which Company File you want to access too:
|
|
86
86
|
|
87
87
|
### API Methods
|
88
88
|
|
89
|
-
Before using the majority of API methods you will need to have selected a Company File. If you've already selected one when creating the client, feel free to ignore this.
|
90
|
-
|
91
89
|
#### Company Files
|
92
90
|
|
93
|
-
|
91
|
+
Before using the majority of API methods you will need to have selected a Company File. If you've already selected one when creating the client, feel free to ignore this.
|
92
|
+
|
93
|
+
Return a list of company files:
|
94
94
|
|
95
95
|
api_client.company_file.all
|
96
96
|
|
@@ -120,6 +120,20 @@ Return a list of all employees
|
|
120
120
|
|
121
121
|
api_client.employee.all
|
122
122
|
|
123
|
+
#### Creating an entity
|
124
|
+
|
125
|
+
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.
|
126
|
+
|
127
|
+
api_client.employee.save({'FirstName' => 'John', 'LastName' => 'Smith', 'IsIndividual' => true})
|
128
|
+
|
129
|
+
#### Updating an entity
|
130
|
+
|
131
|
+
To update an existing entity, call #save on its model, passing through a hash you got from the API. This hash should include a `UID` parameter (which is included by default when you get the data).
|
132
|
+
|
133
|
+
user = api_client.employee.all["Items"].last
|
134
|
+
user['FirstName'] = 'New First Name'
|
135
|
+
api_client.employee.save(user)
|
136
|
+
|
123
137
|
|
124
138
|
## Todo
|
125
139
|
|
data/lib/myob/api/client.rb
CHANGED
data/lib/myob/api/models/base.rb
CHANGED
@@ -32,15 +32,50 @@ module Myob
|
|
32
32
|
model_data[0] if model_data.length > 0
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def save(object)
|
36
|
+
new_record?(object) ? create(object) : update(object)
|
37
|
+
end
|
38
|
+
|
39
|
+
def url(object = nil)
|
36
40
|
if self.model_route == ''
|
37
41
|
"#{API_URL}"
|
38
42
|
else
|
39
|
-
"#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}"
|
43
|
+
"#{API_URL}#{@client.current_company_file[:id]}/#{self.model_route}#{"/#{object['UID']}" if object && object['UID']}"
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
47
|
+
def new_record?(object)
|
48
|
+
object["UID"].nil? || object["UID"] == ""
|
49
|
+
end
|
50
|
+
|
43
51
|
private
|
52
|
+
def create(object)
|
53
|
+
object = typecast(object)
|
54
|
+
response = @client.connection.post(self.url, {:headers => @client.headers, :body => object.to_json})
|
55
|
+
response.status == 201
|
56
|
+
end
|
57
|
+
|
58
|
+
def update(object)
|
59
|
+
object = typecast(object)
|
60
|
+
response = @client.connection.put(self.url(object), {:headers => @client.headers, :body => object.to_json})
|
61
|
+
response.status == 200
|
62
|
+
end
|
63
|
+
|
64
|
+
def typecast(object)
|
65
|
+
returned_object = object.dup # don't change the original object
|
66
|
+
|
67
|
+
returned_object.each do |key, value|
|
68
|
+
if value.respond_to?(:strftime)
|
69
|
+
returned_object[key] = value.strftime(date_formatter)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
returned_object
|
74
|
+
end
|
75
|
+
|
76
|
+
def date_formatter
|
77
|
+
"%Y-%m-%dT%H:%M:%S"
|
78
|
+
end
|
44
79
|
|
45
80
|
def parse_response(response)
|
46
81
|
JSON.parse(response.body)
|
@@ -48,7 +83,7 @@ module Myob
|
|
48
83
|
|
49
84
|
def process_query(data, query)
|
50
85
|
query.each do |property, value|
|
51
|
-
data.select!{|x| x[property] == value}
|
86
|
+
data.select! {|x| x[property] == value}
|
52
87
|
end
|
53
88
|
data
|
54
89
|
end
|
@@ -5,6 +5,22 @@ module Myob
|
|
5
5
|
def model_route
|
6
6
|
'Payroll/Timesheet'
|
7
7
|
end
|
8
|
+
|
9
|
+
# http://developer.myob.com/api/accountright/v2/payroll/timesheet/
|
10
|
+
# we always want to PUT timesheets, so they are never a "new" record
|
11
|
+
def new_record?(object)
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
# a timesheet is identified based on an employee UID as well as its start and end date
|
16
|
+
# it does not have a UID of its own
|
17
|
+
def url(object = nil)
|
18
|
+
if object
|
19
|
+
"#{super()}/#{object['Employee']['UID']}?StartDate=#{object['StartDate']}&EndDate=#{object['EndDate']}"
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
8
24
|
end
|
9
25
|
end
|
10
26
|
end
|
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.2.0
|
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-
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|