mondo 0.4.7 → 0.5.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: 5a021be6a7f394db33923ad600d978572e7e4bf7
4
- data.tar.gz: ec438b3f4c8a29b06c7ee76056746492022a88ef
3
+ metadata.gz: 35b4d2e9ad4815228d09370c38191eaf3caecc53
4
+ data.tar.gz: e7b5d1ac3c629315c1050cf0e732299e79e98370
5
5
  SHA512:
6
- metadata.gz: 3bde4d228c6c3d06106bbb15d08c0ad6df31641f628652c7d2535dff6c0b2d6bba0a8528fc9a38c00fba5b806b9382a3c2947514ab43dc36b1a54621766a7609
7
- data.tar.gz: 526f0663e93bf955c33df8992b5dd65e87d3370cd90d7889bef46791d3bc5ac623e8d8c268d2cb874722f419479b4585dcc3fc90b57fae7496c219e1e22f5175
6
+ metadata.gz: ac914a4546a2ea1a05a22e2e1e0b3762908b3451b5bc56aab73acc5bc46955e96d49dd5d4ed1768522b9f2a2e02b86c7c505d1556c6cf06ad2378d6a2dba6d1d
7
+ data.tar.gz: 5a3f3b33b7e3ee326650e4e4ad594b083e71994008b0ad7d9fc3491bb1f0ddacf3eb9b471fe40b8ac54f345996dee7131b832a0d62dd52e7b23a7b9a403ed109
data/README.md CHANGED
@@ -32,7 +32,7 @@ mondo.ping
32
32
  ```ruby
33
33
  mondo.balance
34
34
 
35
- => {"balance"=>-7708, "currency"=>"GBP", "spend_today"=>-12708}
35
+ => # <Mondo::Balance {"balance"=>642, "currency"=>"GBP", "spend_today"=>0}>}
36
36
  ```
37
37
 
38
38
 
@@ -59,11 +59,9 @@ mondo.transactions(expand: [:merchant], limit: 2, since: "2015-08-10T23:00:00Z")
59
59
  mondo.transaction(tx_00008zvemPnUEdNo8attNB)
60
60
  => #<Mondo::Transaction -5GBP PRET A MANGER LONDON GBR tx_00008zvemPnUEdNo8attNB>
61
61
 
62
-
63
- # TODO - make a Merchant object
64
62
  mondo.transactions.last.merchant
65
63
  =>
66
- #<Mondo::Merchant merch_000090ER75UzBxejYTIb4r {"id"=>"merch_000090ER75UzBxejYTIb4r", "group_id"=>"grp_00008yEdfHhvbwnQcsYryL", "created"=>"2015-09-19T09:42:16Z", "name"=>"Department Of Coffee And Social Affairs", "logo"=>"http://avatars.io/twitter/deptofcoffee/?size=large", "address"=>{"address"=>"14-16 Leather Ln", "city"=>"London", "region"=>"Greater London", "country"=>"GB", "postcode"=>"EC1N 7SU", "latitude"=>51.519348553897686, "longitude"=>-0.1090317964553833}}>
64
+ #<Mondo::Merchant merch_000090ER75UzBxejYTIb4r {"id"=>"merch_000090ER75UzBxejYTIb4r", "group_id"=>"grp_00008yEdfHhvbwnQcsYryL", "created"=>"2015-09-19T09:42:16Z", "name"=>"Department Of Coffee And Social Affairs", "logo"=>"http://avatars.io/twitter/deptofcoffee/?size=large", "address"=>{"address"=>"14-16 Leather Ln", "city"=>"London", "region"=>"Greater London", "country"=>"GB", "postcode"=>"EC1N 7SU", "latitude"=>51.519348553897686, "longitude"=>-0.1090317964553833}}>
67
65
  ```
68
66
 
69
67
  ## Update Transaction Tags
@@ -85,14 +83,14 @@ tx.save_metadata
85
83
  tx = mondo.transactions.first
86
84
 
87
85
  tx.register_attachment(
88
- file_url: "https://example.com/nyannyan.jpg",
86
+ file_url: "https://example.com/nyannyan.jpg",
89
87
  file_type: "image/jpg"
90
88
  )
91
89
 
92
90
  => [#<Mondo::Attachment {"id"=>"attach_00009253YR2h9Besgp6aLR", "url"=>"https://example.com/nyannyan.jpg", "type"=>"image/jpg", "created"=>"2015-11-13T16:50:05Z"}>]
93
91
 
94
92
  # And remove it again
95
- tx.attachments.first.deregsiter
93
+ tx.attachments.first.deregister
96
94
  ```
97
95
 
98
96
 
@@ -115,16 +113,41 @@ mondo.web_hooks.first.delete
115
113
 
116
114
  ```
117
115
 
116
+ ## Cards
117
+
118
+ ```ruby
119
+ mondo.cards
120
+ => [
121
+ #<Mondo::Card {"id"=>"card_000000", "processor_token"=>"1234", "processor"=>"gps", "account_id"=>"account_12345", "last_digits"=>"4242", "name"=>"Your Name", "expires"=>"01/2220", "status"=>"ACTIVE", "created"=>"2016-01-20T17:23:05.51Z"}>
122
+ ]
123
+ ```
124
+
125
+ #### Freeze Card
126
+ ```ruby
127
+ card.freeze
128
+ ```
129
+
130
+ #### Unfreeze Card
131
+ ```ruby
132
+ card.unfreeze
133
+ ```
134
+
118
135
  ## Feed Items
119
136
 
120
137
  ```ruby
121
138
  # Create a new feed item
122
139
 
123
140
  mondo.create_feed_item(
124
- title: "Foo",
141
+ title: "Foo",
125
142
  image_url: "https://www.example.com/img.jpg", # small icon shown in the feed
126
143
  url: "https://www.example.com", # when feed item is clicked, show this page in a webview
127
144
  )
145
+ ```
128
146
 
147
+ ## Tests
129
148
 
130
- ```
149
+ We need some tests. See "Contributing"
150
+
151
+ ## Contributing
152
+
153
+ Pull requests welcome!
@@ -10,6 +10,8 @@ module Mondo
10
10
  require 'mondo/transaction'
11
11
  require 'mondo/feed_item'
12
12
 
13
+ require 'mondo/card'
14
+ require 'mondo/balance'
13
15
  require 'mondo/address'
14
16
  require 'mondo/transaction'
15
17
  require 'mondo/account'
@@ -1,8 +1,12 @@
1
1
  module Mondo
2
2
  class Account < Resource
3
3
 
4
- attr_accessor :id, :description, :raw_data
4
+ attr_accessor :id, :description, :raw_data, :sort_code, :account_number
5
5
 
6
6
  date_accessor :created
7
+
8
+ def balance
9
+ self.client.balance(id)
10
+ end
7
11
  end
8
12
  end
@@ -1,6 +1,6 @@
1
1
  module Mondo
2
2
  class Address < Resource
3
3
  attr_accessor :address, :city, :region, :country, :postcode, :latitude,
4
- :longitude, :raw_data
4
+ :longitude, :raw_data, :short_formatted, :formatted
5
5
  end
6
6
  end
@@ -1,7 +1,7 @@
1
1
  module Mondo
2
2
  class Attachment < Resource
3
- attr_accessor :id, :user_id, :external_id, :file_url, :file_type
4
-
3
+ attr_accessor :id, :user_id, :external_id, :file_url, :file_type, :url, :type
4
+
5
5
  date_accessor :created
6
6
 
7
7
 
@@ -19,8 +19,8 @@ module Mondo
19
19
  {
20
20
  external_id: self.external_id,
21
21
  file_url: self.file_url,
22
- file_type: self.file_type,
22
+ file_type: self.file_type,
23
23
  }
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -0,0 +1,15 @@
1
+ module Mondo
2
+ class Balance < Resource
3
+ def balance
4
+ Money.new(raw_data['balance'], currency)
5
+ end
6
+
7
+ def spent_today
8
+ Money.new(raw_data['spent_today'], currency)
9
+ end
10
+
11
+ def currency
12
+ Money::Currency.new(raw_data['currency'])
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Mondo
2
+ class Card < Resource
3
+ attr_accessor :id, :processor_token, :processor, :account_id,
4
+ :last_digits, :name, :expires, :status
5
+
6
+ date_accessor :created
7
+
8
+ def active?
9
+ status == 'ACTIVE'
10
+ end
11
+
12
+ def freeze
13
+ self.client.api_put("/card/toggle", {
14
+ card_id: id,
15
+ status: 'INACTIVE'
16
+ })
17
+ end
18
+
19
+ def unfreeze
20
+ self.client.api_put("/card/toggle", {
21
+ card_id: id,
22
+ status: 'ACTIVE'
23
+ })
24
+ end
25
+ end
26
+ end
@@ -7,6 +7,7 @@ require 'uri'
7
7
  require 'cgi'
8
8
  require 'time'
9
9
  require 'base64'
10
+ require 'money'
10
11
 
11
12
  module Mondo
12
13
  class Client
@@ -99,32 +100,47 @@ module Mondo
99
100
  # @return [Accounts] all accounts for this user
100
101
  def accounts(opts = {})
101
102
  resp = api_get("/accounts", opts)
102
- return resp unless resp.error.nil?
103
+ return resp if resp.error.present?
103
104
  resp.parsed["accounts"].map { |acc| Account.new(acc, self) }
104
105
  end
105
106
 
107
+ # @method cards
108
+ # @return [Cards] all cards for this user
109
+ def cards(opts = {})
110
+ raise ClientError.new("You must provide an account id to query transactions") unless self.account_id
111
+ opts.merge!(account_id: self.account_id)
112
+ resp = api_get("/card/list", opts)
113
+ return resp if resp.error.present?
114
+ resp.parsed["cards"].map { |tx| Card.new(tx, self) }
115
+ end
116
+
106
117
  # @method transactions
107
118
  # @return [Transactions] all transactions for this user
108
119
  def transactions(opts = {})
109
120
  raise ClientError.new("You must provide an account id to query transactions") unless self.account_id
110
121
  opts.merge!(account_id: self.account_id)
111
122
  resp = api_get("/transactions", opts)
112
- return resp unless resp.error.nil?
123
+ return resp if resp.error.present?
113
124
  resp.parsed["transactions"].map { |tx| Transaction.new(tx, self) }
114
125
  end
115
126
 
116
127
  # @method transaction
117
128
  # @return <Transaction> of the transaction information
118
129
  def transaction(transaction_id, opts = {})
130
+ raise ClientError.new("You must provide an transaction id to query transactions") unless transaction_id
119
131
  resp = api_get("/transactions/#{transaction_id}", opts)
120
- return resp unless resp.error.nil?
132
+ return resp if resp.error.present?
121
133
  Transaction.new(resp.parsed['transaction'], self)
122
134
  end
123
135
 
124
- # Returns {"balance"=>-7708, "currency"=>"GBP", "spend_today"=>-12708}
125
- def balance
126
- raise ClientError.new("You must provide an account id to see your balance") unless self.account_id
127
- api_get("balance", account_id: self.account_id).parsed
136
+ # @method balance
137
+ # @return <Balance> of the balance information
138
+ def balance(account_id = nil)
139
+ account_id ||= self.account_id
140
+ raise ClientError.new("You must provide an account id to see your balance") unless account_id
141
+ resp = api_get("balance", account_id: account_id)
142
+ return resp if resp.error.present?
143
+ Balance.new(resp.parsed, self)
128
144
  end
129
145
 
130
146
  def create_feed_item(params)
@@ -137,7 +153,7 @@ module Mondo
137
153
  {
138
154
  account_id: self.account_id,
139
155
  url: url
140
- },
156
+ },
141
157
  self
142
158
  )
143
159
  hook.save
@@ -218,4 +234,3 @@ module Mondo
218
234
  end
219
235
  end
220
236
  end
221
-
@@ -3,6 +3,8 @@ module Mondo
3
3
 
4
4
  attr_accessor :id, :group_id, :logo, :name, :raw_data, :address, :emoji
5
5
 
6
+ boolean_accessor :online, :is_load, :settled
7
+
6
8
  date_accessor :created
7
9
 
8
10
  def address
@@ -10,7 +10,7 @@ module Mondo
10
10
  self.to_s
11
11
  end
12
12
 
13
- def to_s
13
+ def to_s
14
14
  "#<#{self.class} #{raw_data}>"
15
15
  end
16
16
 
@@ -22,15 +22,30 @@ module Mondo
22
22
  def date_writer(*args)
23
23
  args.each do |attr|
24
24
  define_method("#{attr.to_s}=".to_sym) do |date|
25
- date = date.is_a?(String) ? DateTime.parse(date) : date
25
+ date = (date.is_a?(String) ? DateTime.parse(date) : date) rescue date
26
26
  instance_variable_set("@#{attr}", date)
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
31
  def date_accessor(*args)
32
- attr_reader *args
33
- date_writer *args
32
+ attr_reader(*args)
33
+ date_writer(*args)
34
+ end
35
+
36
+ def boolean_accessor(*attrs)
37
+ attr_accessor(*attrs)
38
+ alias_question(attrs)
39
+ end
40
+
41
+ def boolean_reader(*attrs)
42
+ attr_reader(*attrs)
43
+ alias_question(attrs)
44
+ end
45
+
46
+ private
47
+ def alias_question(attrs)
48
+ attrs.each{ |attr| define_method("#{attr}?"){ send(attr) || false } }
34
49
  end
35
50
  end
36
51
  end
@@ -3,16 +3,38 @@ module Mondo
3
3
 
4
4
  attr_accessor :id,
5
5
  :description,
6
- :amount,
7
- :currency,
8
6
  :notes,
9
- :metadata
7
+ :metadata,
8
+ :is_load,
9
+ :category,
10
+ :settled,
11
+ :decline_reason
10
12
 
11
13
  date_accessor :created
14
+ date_accessor :settled
12
15
 
13
- # TODO - proper currency library
14
- def amount_with_currency
15
- "#{amount/100}#{currency}"
16
+ def declined?
17
+ raw_data['decline_reason'].present?
18
+ end
19
+
20
+ def amount
21
+ Money.new(raw_data['amount'], currency)
22
+ end
23
+
24
+ def local_amount
25
+ Money.new(raw_data['local_amount'], local_currency)
26
+ end
27
+
28
+ def account_balance
29
+ Money.new(raw_data['account_balance'], currency)
30
+ end
31
+
32
+ def currency
33
+ Money::Currency.new(raw_data['currency'])
34
+ end
35
+
36
+ def local_currency
37
+ Money::Currency.new(raw_data['local_currency'])
16
38
  end
17
39
 
18
40
  def save_metadata
@@ -1,3 +1,3 @@
1
1
  module Mondo
2
- VERSION = '0.4.7'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -2,6 +2,7 @@ require File.expand_path('../lib/mondo/version', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.add_runtime_dependency 'oauth2', '~> 1.0'
5
+ gem.add_runtime_dependency 'money'
5
6
  gem.add_runtime_dependency 'multi_json', '~> 1.10'
6
7
 
7
8
  gem.add_development_dependency 'rspec', '~> 2.13'
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.7
4
+ version: 0.5.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-15 00:00:00.000000000 Z
11
+ date: 2016-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: money
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: multi_json
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +128,8 @@ files:
114
128
  - lib/mondo/account.rb
115
129
  - lib/mondo/address.rb
116
130
  - lib/mondo/attachment.rb
131
+ - lib/mondo/balance.rb
132
+ - lib/mondo/card.rb
117
133
  - lib/mondo/client.rb
118
134
  - lib/mondo/errors.rb
119
135
  - lib/mondo/feed_item.rb