mondo 0.3.3 → 0.4.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/lib/mondo/account.rb +8 -0
- data/lib/mondo/attachment.rb +22 -0
- data/lib/mondo/client.rb +20 -1
- data/lib/mondo/errors.rb +4 -2
- data/lib/mondo/feed_item.rb +1 -1
- data/lib/mondo/transaction.rb +19 -0
- data/lib/mondo/version.rb +1 -1
- data/lib/mondo.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ed5dcc373f5e53cd3d24148159811756031dffd
|
4
|
+
data.tar.gz: a57ec85fa9a477b5331008309ee083a983e90d16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b9ae27325edb38750e6bdc5ecbde9d36c67a2f8740c1d950f2d5af687067345b23384e04a3bc35a728d85ecff1a20752cdd41b0ad2f2c9e1fe618a1bee61ed9
|
7
|
+
data.tar.gz: 5793f8c3f501157bd7f9041a82bbf0ec9598170d6f6681b394e26a271a66ae7bec15bd58df79bf340e9f21c0ceb0dd10681f59f0cebe98b4bb65a80819f5c44e
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mondo
|
2
|
+
class Attachment < Resource
|
3
|
+
attr_accessor :id, :user_id, :external_id, :file_url, :file_type
|
4
|
+
|
5
|
+
date_accessor :created
|
6
|
+
|
7
|
+
|
8
|
+
def register
|
9
|
+
raise ClientError.new("You have already registered this attachment") unless self.id.nil?
|
10
|
+
|
11
|
+
self.client.api_post("attachment/register", registration_data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def registration_data
|
15
|
+
{
|
16
|
+
external_id: self.external_id,
|
17
|
+
file_url: self.file_url,
|
18
|
+
file_type: self.file_type,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/mondo/client.rb
CHANGED
@@ -18,6 +18,14 @@ module Mondo
|
|
18
18
|
self.account_id = args.fetch(:account_id, nil)
|
19
19
|
self.api_url = args.fetch(:api_url, DEFAULT_API_URL)
|
20
20
|
raise ClientError.new("You must provide a token") unless self.access_token
|
21
|
+
set_account
|
22
|
+
end
|
23
|
+
|
24
|
+
# Hacky
|
25
|
+
def set_account
|
26
|
+
acc = accounts.first
|
27
|
+
return unless acc
|
28
|
+
self.account_id = acc.id
|
21
29
|
end
|
22
30
|
|
23
31
|
# Replies "pong"
|
@@ -85,6 +93,14 @@ module Mondo
|
|
85
93
|
request(method, path, opts)
|
86
94
|
end
|
87
95
|
|
96
|
+
# @method accounts
|
97
|
+
# @return [Accounts] all accounts for this user
|
98
|
+
def accounts(opts = {})
|
99
|
+
resp = api_get("/accounts", opts)
|
100
|
+
return resp unless resp.error.nil?
|
101
|
+
resp.parsed["accounts"].map { |acc| Account.new(acc, self) }
|
102
|
+
end
|
103
|
+
|
88
104
|
# @method transactions
|
89
105
|
# @return [Transactions] all transactions for this user
|
90
106
|
def transactions(opts = {})
|
@@ -134,7 +150,10 @@ module Mondo
|
|
134
150
|
opts[:headers]['User-Agent'] = user_agent
|
135
151
|
opts[:headers]['Authorization'] = "Bearer #{@access_token}"
|
136
152
|
|
137
|
-
|
153
|
+
if !opts[:data].nil?
|
154
|
+
opts[:body] = URI.encode_www_form(opts[:data])
|
155
|
+
opts[:headers]['Content-Type'] = 'application/x-www-form-urlencoded' # sob sob
|
156
|
+
end
|
138
157
|
|
139
158
|
puts opts
|
140
159
|
|
data/lib/mondo/errors.rb
CHANGED
@@ -11,9 +11,11 @@ module Mondo
|
|
11
11
|
@response = response
|
12
12
|
@code = response.status
|
13
13
|
|
14
|
+
puts response.inspect
|
15
|
+
|
14
16
|
begin
|
15
17
|
parsed_response = MultiJson.decode(response.body)
|
16
|
-
errors = parsed_response["
|
18
|
+
errors = parsed_response["message"]
|
17
19
|
@description = stringify_errors(errors)
|
18
20
|
rescue MultiJson::ParseError
|
19
21
|
@description = response.body ? response.body.strip : "Unknown error"
|
@@ -21,7 +23,7 @@ module Mondo
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def to_s
|
24
|
-
"#{super}
|
26
|
+
"#{super}. #{self.description}"
|
25
27
|
end
|
26
28
|
|
27
29
|
private
|
data/lib/mondo/feed_item.rb
CHANGED
data/lib/mondo/transaction.rb
CHANGED
@@ -19,6 +19,25 @@ module Mondo
|
|
19
19
|
self.client.api_patch("/transactions/#{self.id}", metadata: self.metadata)
|
20
20
|
end
|
21
21
|
|
22
|
+
def register_attachment(args={})
|
23
|
+
attachment = Attachment.new(
|
24
|
+
{
|
25
|
+
external_id: self.id,
|
26
|
+
file_url: args.fetch(:file_url),
|
27
|
+
file_type: args.fetch(:file_type)
|
28
|
+
},
|
29
|
+
self.client
|
30
|
+
)
|
31
|
+
|
32
|
+
self.attachments << attachment if attachment.register
|
33
|
+
end
|
34
|
+
|
35
|
+
def attachments
|
36
|
+
@transactions ||= begin
|
37
|
+
raw_data['attachments'].map { |tx| Attachment.new(tx, self.client) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
22
41
|
def merchant(opts={})
|
23
42
|
unless raw_data['merchant'].kind_of?(Hash)
|
24
43
|
# Go and refetch the transaction with merchant info expanded
|
data/lib/mondo/version.rb
CHANGED
data/lib/mondo.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mondo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Blomfield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -111,7 +111,9 @@ files:
|
|
111
111
|
- README.md
|
112
112
|
- Rakefile
|
113
113
|
- lib/mondo.rb
|
114
|
+
- lib/mondo/account.rb
|
114
115
|
- lib/mondo/address.rb
|
116
|
+
- lib/mondo/attachment.rb
|
115
117
|
- lib/mondo/client.rb
|
116
118
|
- lib/mondo/errors.rb
|
117
119
|
- lib/mondo/feed_item.rb
|