mondo 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3290bf5d93277889046409e472c78d423e01e72b
4
- data.tar.gz: fbab72d4137363459754d250dd2e801c135735b1
3
+ metadata.gz: 6ed5dcc373f5e53cd3d24148159811756031dffd
4
+ data.tar.gz: a57ec85fa9a477b5331008309ee083a983e90d16
5
5
  SHA512:
6
- metadata.gz: bc42761b9ca66c9c7d0a1311694bcf81b891f0dd1c1b1b663696c489b3845067483cca2d3c55fb67d0844933cc9b87e32ff320ff71ca77db376ab6c16ffa4805
7
- data.tar.gz: f449bb4022cfca75c84bf8158911eecd7009991c0fd7fd17fa7156df510916d8d8c15b9979ea79ca15195663d0245672f25ae43e0e0c2799807a02638a067c19
6
+ metadata.gz: 3b9ae27325edb38750e6bdc5ecbde9d36c67a2f8740c1d950f2d5af687067345b23384e04a3bc35a728d85ecff1a20752cdd41b0ad2f2c9e1fe618a1bee61ed9
7
+ data.tar.gz: 5793f8c3f501157bd7f9041a82bbf0ec9598170d6f6681b394e26a271a66ae7bec15bd58df79bf340e9f21c0ceb0dd10681f59f0cebe98b4bb65a80819f5c44e
@@ -0,0 +1,8 @@
1
+ module Mondo
2
+ class Account < Resource
3
+
4
+ attr_accessor :id, :description, :raw_data
5
+
6
+ date_accessor :created
7
+ end
8
+ end
@@ -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
- opts[:body] = MultiJson.encode(opts[:data]) if !opts[:data].nil?
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["error"] || parsed_response["errors"]
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} [#{self.code}] #{self.description}"
26
+ "#{super}. #{self.description}"
25
27
  end
26
28
 
27
29
  private
@@ -8,7 +8,7 @@ module Mondo
8
8
  :body
9
9
 
10
10
 
11
- # temporary fix until the API accepts data in the request body
11
+ # temporary fix until the API accepts JSON data in the request body
12
12
  def save
13
13
  self.client.request(:post, "/feed", params: self.create_params)
14
14
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Mondo
2
- VERSION = '0.3.3'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
data/lib/mondo.rb CHANGED
@@ -12,5 +12,7 @@ module Mondo
12
12
 
13
13
  require 'mondo/address'
14
14
  require 'mondo/transaction'
15
+ require 'mondo/account'
15
16
  require 'mondo/merchant'
17
+ require 'mondo/attachment'
16
18
  end
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.3.3
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-09-20 00:00:00.000000000 Z
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