localbitcoins 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +13 -5
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +16 -19
  4. data/README.md +319 -35
  5. data/Rakefile +1 -1
  6. data/lib/localbitcoins/client/ads.rb +45 -9
  7. data/lib/localbitcoins/client/contacts.rb +66 -0
  8. data/lib/localbitcoins/client/escrows.rb +8 -12
  9. data/lib/localbitcoins/client/markets.rb +27 -0
  10. data/lib/localbitcoins/client/public.rb +78 -0
  11. data/lib/localbitcoins/client/users.rb +16 -0
  12. data/lib/localbitcoins/client/wallet.rb +28 -0
  13. data/lib/localbitcoins/client.rb +13 -1
  14. data/lib/localbitcoins/request.rb +11 -15
  15. data/lib/localbitcoins/version.rb +1 -1
  16. data/localbitcoins.gemspec +3 -3
  17. data/spec/client_spec.rb +397 -8
  18. data/spec/fixtures/account_info.json +14 -0
  19. data/spec/fixtures/ad_create.json +5 -0
  20. data/spec/fixtures/ad_list.json +103 -0
  21. data/spec/fixtures/ad_single.json +55 -0
  22. data/spec/fixtures/ad_update.json +5 -0
  23. data/spec/fixtures/ads.json +103 -0
  24. data/spec/fixtures/contact_message.json +5 -0
  25. data/spec/fixtures/contacts.json +52 -0
  26. data/spec/fixtures/contacts_active.json +165 -0
  27. data/spec/fixtures/contacts_active_buyers.json +60 -0
  28. data/spec/fixtures/contacts_active_sellers.json +111 -0
  29. data/spec/fixtures/contacts_cancel.json +5 -0
  30. data/spec/fixtures/contacts_canceled_contacts.json +162 -0
  31. data/spec/fixtures/contacts_closed_contacts.json +109 -0
  32. data/spec/fixtures/contacts_contact_info.json +52 -0
  33. data/spec/fixtures/contacts_contacts_info.json +111 -0
  34. data/spec/fixtures/contacts_create.json +10 -0
  35. data/spec/fixtures/contacts_messages.json +43 -0
  36. data/spec/fixtures/contacts_released_contacts.json +60 -0
  37. data/spec/fixtures/currencies.json +505 -0
  38. data/spec/fixtures/currency_ticker.json +236 -0
  39. data/spec/fixtures/escrow_release.json +5 -0
  40. data/spec/fixtures/escrows.json +24 -22
  41. data/spec/fixtures/local_buy_ads.json +93 -0
  42. data/spec/fixtures/local_sell_ads.json +93 -0
  43. data/spec/fixtures/logout.json +0 -0
  44. data/spec/fixtures/myself.json +14 -0
  45. data/spec/fixtures/online_buy_ads.json +637 -0
  46. data/spec/fixtures/online_sell_ads.json +2160 -0
  47. data/spec/fixtures/orderbook.json +1739 -0
  48. data/spec/fixtures/payment_methods.json +95 -0
  49. data/spec/fixtures/places.json +15 -0
  50. data/spec/fixtures/ticker.json +254 -0
  51. data/spec/fixtures/trades.json +3002 -0
  52. data/spec/fixtures/wallet.json +34 -0
  53. data/spec/fixtures/wallet_addr.json +6 -0
  54. data/spec/fixtures/wallet_balance.json +16 -0
  55. data/spec/fixtures/wallet_send.json +5 -0
  56. data/spec/spec_helper.rb +26 -29
  57. metadata +51 -7
data/spec/client_spec.rb CHANGED
@@ -10,18 +10,407 @@ describe 'Client' do
10
10
 
11
11
  describe "#escrows" do
12
12
  before do
13
- stub_get('/api/escrows/', 'escrows.json')
13
+ stub_get('/api/escrows/','escrows.json')
14
+ stub_post('/api/escrow_release/12345/', 'escrow_release.json')
14
15
  end
15
16
 
16
- it 'returns escrows owner of the access token can release' do
17
+ it 'returns escrows, which the owner of the access token can release' do
17
18
  expect { client.escrows }.not_to raise_error
18
19
 
19
20
  escrows = client.escrows
20
- escrows.should be_a Hashie::Mash
21
- escrows.escrow_list[0].data.buyer_username.should eq "alice"
22
- escrows.escrow_list[0].data.reference_code.should eq "123"
23
- escrows.escrow_list[1].data.reference_code.should eq "456"
24
- escrows.escrow_list[1].actions.release_url.should eq "/api/escrow_release/2/"
21
+ expect(escrows).to be_a Hashie::Mash
22
+ expect(escrows.escrow_list[0].data.buyer_username).to eq "alice"
23
+ expect(escrows.escrow_list[0].data.reference_code).to eq "123"
24
+ expect(escrows.escrow_list[1].data.reference_code).to eq "456"
25
+ expect(escrows.escrow_list[1].actions.release_url).to eq "/api/escrow_release/2/"
26
+ end
27
+
28
+ it 'returns a success message indicating the escrow has been released' do
29
+ expect { client.escrow_release('12345') }.not_to raise_error
30
+ message = client.escrow_release('12345')
31
+ expect(message).to be_a Hashie::Mash
32
+ expect(message.message).to eq "The escrow has been released successfully."
33
+
34
+ end
35
+ end
36
+
37
+ describe "#ads" do
38
+ before do
39
+ stub_get('/api/ads/', 'ads.json')
40
+ stub_post('/api/ad/12345/', 'ad_update.json')
41
+ stub_get('/api/ad-get/12345/', 'ad_single.json')
42
+ stub_post('/api/ad-create/', 'ad_create.json')
43
+ stub_get('/api/ad-get/', 'ad_list.json',{:ads=>"12345,123456"})
44
+ end
45
+
46
+ it 'returns listing of the token owners ads' do
47
+ expect { client.ads }.not_to raise_error
48
+ ads = client.ads
49
+ expect(ads).to be_a Hashie::Mash
50
+ expect(ads.ad_count).to eq 2
51
+ expect(ads.ad_list[0].data.ad_id).to eq 12345
52
+ expect(ads.ad_list[1].data.ad_id).to eq 123456
53
+ expect(ads.ad_list[0].data.location_string).to eq "Puerto Vallarta, JAL, Mexico"
54
+ expect(ads.ad_list[0].data.profile.username).to eq "Bob"
55
+ expect(ads.ad_list[0].actions.contact_form).to eq "https://localbitcoins.com/api/contact_create/12345/"
56
+ expect(ads.ad_list[1].data.atm_model).to eq nil
57
+ end
58
+
59
+ it 'returns success message if the ad was updated' do
60
+ expect { client.update_ad(12345,{:price_equation => "localbitcoins_sell_usd"}) }.not_to raise_error
61
+ ad_update = client.update_ad(12345,{:price_equation => "localbitcoins_sell_usd"})
62
+ expect(ad_update).to be_a Hashie::Mash
63
+ expect(ad_update.message).to eq "Ad changed successfully!"
64
+ end
65
+
66
+ it 'returns success message if the ad was created' do
67
+ expect { client.create_ad({}) }.not_to raise_error
68
+ ad_create = client.create_ad({})
69
+ expect(ad_create).to be_a Hashie::Mash
70
+ expect(ad_create.message).to eq "Ad added successfully!"
71
+ end
72
+
73
+ it 'returns listing of ads from passed ids' do
74
+ expect { client.ad_list("12345,123456") }.not_to raise_error
75
+ ad_list = client.ad_list("12345,123456")
76
+ expect(ad_list).to be_a Hashie::Mash
77
+ expect(ad_list.count).to eq 2
78
+ expect(ad_list.ad_list[0].data.ad_id).to eq 12345
79
+ expect(ad_list.ad_list[1].data.ad_id).to eq 123456
80
+ end
81
+
82
+ it 'returns ad from passed id' do
83
+ expect { client.ad("12345") }.not_to raise_error
84
+ ad = client.ad("12345")
85
+ expect(ad).to be_a Hashie::Mash
86
+ expect(ad.count).to eq 2
87
+ expect(ad.ad_list[0].data.ad_id).to eq 12345
88
+ expect(ad.ad_count).to eq 1
89
+ end
90
+ end
91
+
92
+ describe "#wallet" do
93
+ before do
94
+ stub_get('/api/wallet/', 'wallet.json')
95
+ stub_get('/api/wallet-balance/', 'wallet_balance.json')
96
+ stub_post('/api/wallet-send/', 'wallet_send.json')
97
+ stub_post('/api/wallet-addr/', 'wallet_addr.json')
98
+ end
99
+
100
+ it 'returns information about the token owners wallet' do
101
+ expect { client.wallet }.not_to raise_error
102
+ wallet = client.wallet
103
+ expect(wallet).to be_a Hashie::Mash
104
+ expect(wallet.total.balance).to eq "0.05"
105
+ expect(wallet.total.sendable).to eq "0.05"
106
+ expect(wallet.receiving_address_list[0].address).to eq "15HfUY9LwwewaWwrKRXzE91tjDnHmye1hc"
107
+ end
108
+
109
+ it 'returns balance information for the token owners wallet' do
110
+ expect { client.wallet_balance }.not_to raise_error
111
+ wallet_balance = client.wallet_balance
112
+ expect(wallet_balance).to be_a Hashie::Mash
113
+ expect(wallet_balance.message).to eq "ok"
114
+ expect(wallet_balance.total.balance).to eq "0.05"
115
+ expect(wallet_balance.total.sendable).to eq "0.05"
116
+ expect(wallet_balance.receiving_address_list[0].address).to eq "15HfUY9LwwewaWwrKRXzE91tjDnHmye1hc"
117
+ end
118
+
119
+ it 'returns confirmation message for sending btc' do
120
+ expect { client.wallet_send("15HfUY9LwwewaWwrKRXzE91tjDnHmy2d2hc","0.001") }.not_to raise_error
121
+ wallet_send = client.wallet_send("15HfUY9LwwewaWwrKRXzE91tjDnHmy2d2hc","0.001")
122
+ expect(wallet_send).to be_a Hashie::Mash
123
+ expect(wallet_send.message).to eq "Money is being sent"
124
+ end
125
+
126
+ it 'returns unused wallet address from token owners wallet' do
127
+ expect { client.wallet_addr }.not_to raise_error
128
+ wallet_address = client.wallet_addr
129
+ expect(wallet_address.address).to eq "15HfUY9LwwewaWwrKRXzE91tjDnHmy2d2hc"
130
+ expect(wallet_address.message).to eq "OK!"
131
+ end
132
+ end
133
+
134
+ describe "#contacts" do
135
+ before do
136
+ stub_post('/api/contact_message_post/12345/', 'contact_message.json')
137
+ stub_get('/api/dashboard/', 'contacts_active.json')
138
+ stub_get('/api/dashboard/buyer/', 'contacts_active_buyers.json')
139
+ stub_get('/api/dashboard/seller/', 'contacts_active_sellers.json')
140
+ stub_get('/api/dashboard/released/', 'contacts_released_contacts.json')
141
+ stub_get('/api/dashboard/canceled/', 'contacts_canceled_contacts.json')
142
+ stub_get('/api/dashboard/closed/', 'contacts_canceled_contacts.json')
143
+ stub_get('/api/contact_messages/12345/', 'contacts_messages.json')
144
+ stub_post('/api/contact_cancel/12345/','contacts_cancel.json')
145
+ stub_post('/api/contact_create/12345/', 'contacts_create.json')
146
+ stub_get('/api/contact_info/12345/', 'contacts_contact_info.json')
147
+ stub_get('/api/contact_info/', 'contacts_contacts_info.json', {:contacts=>"12345,54321"})
148
+ end
149
+
150
+ it 'returns confirmation for sending a message' do
151
+ expect { client.message_contact('12345', 'Text of the message.') }.not_to raise_error
152
+ contact_message = client.message_contact('12345', 'Text of the message.')
153
+ expect(contact_message).to be_a Hashie::Mash
154
+ expect(contact_message.message).to eq "Message sent successfully."
155
+ end
156
+
157
+ it 'returns active contact list for token owner' do
158
+ expect { client.active_contacts }.not_to raise_error
159
+ active_contacts = client.active_contacts
160
+ expect(active_contacts).to be_a Hashie::Mash
161
+ expect(active_contacts.contact_count).to eq 3
162
+ expect(active_contacts.contact_list[0].data.currency).to eq "MXN"
163
+ expect(active_contacts.contact_list[1].data.currency).to eq "MXN"
164
+ expect(active_contacts.contact_list[2].data.currency).to eq "USD"
165
+ expect(active_contacts.contact_list[0].data.amount).to eq "1.00"
166
+ expect(active_contacts.contact_list[1].data.amount).to eq "2.00"
167
+ expect(active_contacts.contact_list[2].data.amount).to eq "0.10"
168
+ expect(active_contacts.contact_list[0].data.advertisement.id).to eq 1234567
169
+ expect(active_contacts.contact_list[1].data.advertisement.id).to eq 1234567
170
+ expect(active_contacts.contact_list[2].data.advertisement.id).to eq 1234567
171
+ expect(active_contacts.contact_list[0].data.advertisement.advertiser.username).to eq "Bob"
172
+ expect(active_contacts.contact_list[1].data.advertisement.advertiser.username).to eq "Bob"
173
+ expect(active_contacts.contact_list[2].data.advertisement.advertiser.username).to eq "Alice"
174
+ expect(active_contacts.contact_list[0].data.is_selling).to eq true
175
+ expect(active_contacts.contact_list[1].data.is_selling).to eq true
176
+ expect(active_contacts.contact_list[2].data.is_selling).to eq false
177
+ expect(active_contacts.contact_list[0].data.is_buying).to eq false
178
+ expect(active_contacts.contact_list[1].data.is_buying).to eq false
179
+ expect(active_contacts.contact_list[2].data.is_buying).to eq true
180
+ end
181
+
182
+ it 'returns active buyer contacts for token owner' do
183
+ expect { client.active_contacts('buyer') }.not_to raise_error
184
+ active_buyer_contacts = client.active_contacts('buyer')
185
+ expect(active_buyer_contacts).to be_a Hashie::Mash
186
+ expect(active_buyer_contacts.contact_count).to eq 1
187
+ expect(active_buyer_contacts.contact_list[0].data.advertisement.id).to eq 123456
188
+ expect(active_buyer_contacts.contact_list[0].data.advertisement.advertiser.username).to eq "Alice"
189
+ expect(active_buyer_contacts.contact_list[0].data.contact_id).to eq 543210
190
+ end
191
+
192
+ it 'returns active seller contacts for token owner' do
193
+ expect { client.active_contacts('seller') }.not_to raise_error
194
+ active_seller_contacts = client.active_contacts('seller')
195
+ expect(active_seller_contacts).to be_a Hashie::Mash
196
+ expect(active_seller_contacts.contact_count).to eq 2
197
+ expect(active_seller_contacts.contact_list[0].data.currency).to eq "MXN"
198
+ expect(active_seller_contacts.contact_list[1].data.currency).to eq "MXN"
199
+ expect(active_seller_contacts.contact_list[0].data.payment_completed_at).to eq nil
200
+ end
201
+
202
+ it 'returns list of released contacts' do
203
+ expect { client.released_contacts }.not_to raise_error
204
+ released_contacts = client.released_contacts
205
+ expect(released_contacts).to be_a Hashie::Mash
206
+ expect(released_contacts.contact_count).to eq 1
207
+ expect(released_contacts.contact_list[0].data.advertisement.id).to eq 123456
208
+ expect(released_contacts.contact_list[0].data.advertisement.advertiser.username).to eq "Alice"
209
+ expect(released_contacts.contact_list[0].data.contact_id).to eq 543210
210
+ end
211
+
212
+ it 'returns list of canceled contacts' do
213
+ expect { client.canceled_contacts }.not_to raise_error
214
+ canceled_contacts = client.canceled_contacts
215
+ expect(canceled_contacts).to be_a Hashie::Mash
216
+ expect(canceled_contacts.contact_count).to eq 3
217
+ expect(canceled_contacts.contact_list[0].data.advertisement.advertiser.username).to eq "Bob"
218
+ expect(canceled_contacts.contact_list[2].data.advertisement.advertiser.username).to eq "Bob"
219
+ expect(canceled_contacts.contact_list[0].data.canceled_at).to eq "2014-06-19T20:34:18+00:00"
220
+ expect(canceled_contacts.contact_list[2].data.canceled_at).to eq "2014-06-19T18:56:45+00:00"
221
+ expect(canceled_contacts.contact_list[1].data.amount).to eq "108.46"
222
+ expect(canceled_contacts.contact_list[2].data.amount).to eq "100.02"
223
+ end
224
+
225
+ it 'returns list of closed contacts' do
226
+ expect { client.closed_contacts }.not_to raise_error
227
+ closed_contacts = client.closed_contacts
228
+ expect(closed_contacts).to be_a Hashie::Mash
229
+ expect(closed_contacts.contact_count).to eq 3
230
+ expect(closed_contacts.contact_list[0].data.advertisement.advertiser.username).to eq "Bob"
231
+ expect(closed_contacts.contact_list[2].data.advertisement.advertiser.username).to eq "Bob"
232
+ expect(closed_contacts.contact_list[0].data.canceled_at).to eq "2014-06-19T20:34:18+00:00"
233
+ expect(closed_contacts.contact_list[2].data.canceled_at).to eq "2014-06-19T18:56:45+00:00"
234
+ expect(closed_contacts.contact_list[1].data.amount).to eq "108.46"
235
+ expect(closed_contacts.contact_list[2].data.amount).to eq "100.02"
236
+ end
237
+
238
+ it 'returns list of messages for a contact' do
239
+ expect { client.messages_from_contact('12345') }.not_to raise_error
240
+ contact_messages = client.messages_from_contact('12345')
241
+ expect(contact_messages).to be_a Hashie::Mash
242
+ expect(contact_messages.message_count).to eq 3
243
+ expect(contact_messages.message_list[0].msg).to eq "Message body"
244
+ expect(contact_messages.message_list[1].msg).to eq "Text of the message."
245
+ expect(contact_messages.message_list[0].sender.username).to eq "Bob"
246
+ expect(contact_messages.message_list[2].sender.username).to eq "Alice"
247
+ end
248
+
249
+ it 'returns confirmation on cancellation of a contact' do
250
+ expect { client.cancel_contact('12345') }.not_to raise_error
251
+ cancel_contact = client.cancel_contact('12345')
252
+ expect(cancel_contact).to be_a Hashie::Mash
253
+ expect(cancel_contact.message).to eq "Contact canceled."
254
+ end
255
+
256
+ it 'returns confirmation of contact creation' do
257
+ expect { client.create_contact('12345', '1000', 'Message body') }.not_to raise_error
258
+ create_contact = client.create_contact('12345', '1000', 'Message body')
259
+ expect(create_contact).to be_a Hashie::Mash
260
+ expect(create_contact.data.message).to eq "OK!"
261
+ expect(create_contact.actions.contact_url).to eq "https://localbitcoins.com/api/contact_info/123456/"
262
+ end
263
+
264
+ it 'returns specified contact' do
265
+ expect { client.contact_info(12345) }.not_to raise_error
266
+ contact_info = client.contact_info(12345)
267
+ expect(contact_info.data.advertisement.advertiser.username).to eq "Bob"
268
+ expect(contact_info.data.buyer.username).to eq "Alice"
269
+ expect(contact_info.data.advertisement.id).to eq 1234567
270
+ expect(contact_info.actions.messages_url).to eq "https://localbitcoins.com/api/contact_messages/12345/"
271
+ end
272
+
273
+ it 'returns list of contacts, from specified list' do
274
+ expect { client.contacts_info('12345,54321') }.not_to raise_error
275
+ contacts = client.contacts_info('12345,54321')
276
+ expect(contacts).to be_a Hashie::Mash
277
+ expect(contacts.contact_count).to eq 2
278
+ expect(contacts.contact_list[0].data.advertisement.advertiser.username).to eq "Bob"
279
+ expect(contacts.contact_list[1].data.advertisement.advertiser.username).to eq "Bob"
280
+ expect(contacts.contact_list[0].data.buyer.username).to eq "Alice"
281
+ expect(contacts.contact_list[1].data.buyer.username).to eq "Alice"
282
+ expect(contacts.contact_list[0].actions.cancel_url).to eq "https://localbitcoins.com/api/contact_cancel/12345/"
283
+ end
284
+
285
+ end
286
+
287
+ describe "#users" do
288
+ before do
289
+ stub_get('/api/myself/', 'myself.json')
290
+ stub_get('/api/account_info/bob/', 'account_info.json')
291
+ stub_post('/api/logout/', 'logout.json')
292
+ end
293
+
294
+ it 'returns user information on the token owner' do
295
+ expect { client.myself }.not_to raise_error
296
+ myself = client.myself
297
+ expect(myself.username).to eq "alice"
298
+ expect(myself.has_common_trades).to eq false
299
+ expect(myself.trusted_count).to eq 4
300
+ end
301
+
302
+ it 'returns user information on user with specified username' do
303
+ expect { client.account_info('bob') }.not_to raise_error
304
+ account_info = client.account_info('bob')
305
+ expect(account_info.username).to eq "bob"
306
+ expect(account_info.trade_volume_text).to eq "Less than 25 BTC"
307
+ expect(account_info.url).to eq "https://localbitcoins.com/p/bob/"
308
+ end
309
+
310
+ it 'immediately expires currently authorized access_token' do
311
+ #expect { client.logout }.not_to raise_error
312
+
313
+ end
314
+ end
315
+
316
+ describe "#markets" do
317
+ before do
318
+ stub_get_unauth('/bitcoinaverage/ticker-all-currencies/', 'ticker.json')
319
+ stub_get_unauth('/bitcoincharts/USD/trades.json?since=170892', 'trades.json')
320
+ stub_get_unauth('/bitcoincharts/USD/orderbook.json', 'orderbook.json')
321
+ end
322
+
323
+ it 'returns current bitcoin prices in all currencies' do
324
+ expect { client.ticker }.not_to raise_error
325
+ ticker = client.ticker
326
+ expect(ticker.USD.volume_btc).to eq "701.42"
327
+ expect(ticker.MXN.rates.last).to eq "8431.10"
328
+ expect(ticker.PHP.avg_12h).to eq 24559.67
329
+ end
330
+
331
+ it 'returns last 500 trades in a specified currency since last_tid' do
332
+ expect { client.trades('USD', '170892') }.not_to raise_error
333
+ trades = client.trades('USD', '170892')
334
+ expect(trades).to be_a Array
335
+ expect(trades[0]['tid']).to eq 170892
336
+ expect(trades[-1]['amount']).to eq "1.54970000"
337
+ end
338
+
339
+ it 'immediately expires currently authorized access_token' do
340
+ expect { client.orderbook('USD') }.not_to raise_error
341
+ orderbook = client.orderbook('USD')
342
+ expect(orderbook).to be_a Hashie::Mash
343
+ expect(orderbook.asks[0][1]).to eq "1190.53"
344
+ expect(orderbook.bids[-1][0]).to eq "0.16"
345
+ end
346
+ end
347
+
348
+ describe "#public" do
349
+ before do
350
+ stub_get_unauth('/buy-bitcoins-online/US/usa/moneygram/.json', 'online_buy_ads.json')
351
+ stub_get_unauth('/sell-bitcoins-online/.json', 'online_sell_ads.json')
352
+ stub_get_unauth('/api/payment_methods/us/', 'payment_methods.json')
353
+ stub_get_unauth('/api/currencies/', 'currencies.json')
354
+ stub_get_unauth('/buy-bitcoins-with-cash/214875/48453-mx/.json?lat=20&lon=-105', 'local_buy_ads.json')
355
+ stub_get_unauth('/sell-bitcoins-with-cash/214875/48453-mx/.json?lat=20&lon=-105', 'local_sell_ads.json')
356
+ stub_get_unauth('/api/places/?lat=35&lon=100', 'places.json')
357
+ end
358
+
359
+ it 'shows all online buy ads with given specifications' do
360
+ expect { client.online_buy_ads_lookup({:countrycode => "US", :country_name => "usa", :payment_method => "moneygram"}) }.not_to raise_error
361
+ ads = client.online_buy_ads_lookup({:countrycode => "US", :country_name => "usa", :payment_method => "moneygram"})
362
+ expect(ads).to be_a Hashie::Mash
363
+ expect(ads.data.ad_list[0][:data][:profile][:username]).to eq "btcusd"
364
+ expect(ads.data.ad_count).to eq 15
365
+ end
366
+
367
+ it 'shows all online sell ads with given specifications' do
368
+ expect { client.online_sell_ads_lookup }.not_to raise_error
369
+ ads = client.online_sell_ads_lookup
370
+ expect(ads).to be_a Hashie::Mash
371
+ expect(ads.data.ad_list[0][:data][:created_at]).to eq "2013-09-22T08:50:04+00:00"
372
+ expect(ads.data.ad_list[1][:actions][:public_view]).to eq "https://localbitcoins.com/ad/55455"
373
+ expect(ads.pagination.next).to eq "https://localbitcoins.com/sell-bitcoins-online/.json?temp_price_usd__lt=571.35"
374
+ end
375
+
376
+ it 'shows all payment methods accepted in given countrycode' do
377
+ expect { client.payment_methods('us') }.not_to raise_error
378
+ payment = client.payment_methods('us')
379
+ expect(payment).to be_a Hashie::Mash
380
+ expect(payment[:methods].solidtrustpay.name).to eq "SolidTrustPay"
381
+ expect(payment.method_count).to eq 22
382
+ end
383
+
384
+ it 'shows all currencies used by localbitcoins' do
385
+ expect { client.currencies }.not_to raise_error
386
+ currencies = client.currencies
387
+ expect(currencies.currencies.EGP.name).to eq "Egyptian Pound"
388
+ expect(currencies.currency_count).to eq 166
389
+ end
390
+
391
+ it 'shows all local buy ads with given specifications' do
392
+ expect { client.local_buy_ad({:location_id=>214875, :location_slug=>"48453-MX", :lat=>20, :lon=>-105}) }.not_to raise_error
393
+ ads = client.local_buy_ad({:location_id=>214875, :location_slug=>"48453-MX", :lat=>20, :lon=>-105})
394
+ expect(ads.data.ad_list[0].data.profile.username).to eq "bob"
395
+ expect(ads.data.ad_list[0].data.ad_id).to eq 123456
396
+ expect(ads.data.ad_list[1].data.msg).to eq("Fell in a hole and found a secret and magical world! Bitcoins grow on trees down here ;)")
397
+ end
398
+
399
+ it 'shows all local sell ads with given specifications' do
400
+ expect { client.local_sell_ad({:location_id=>214875, :location_slug=>"48453-MX", :lat=>20, :lon=>-105}) }.not_to raise_error
401
+ ads = client.local_sell_ad({:location_id=>214875, :location_slug=>"48453-MX", :lat=>20, :lon=>-105})
402
+ expect(ads.data.ad_list[0].data.profile.username).to eq "bobby"
403
+ expect(ads.data.ad_list[0].data.ad_id).to eq 12345
404
+ expect(ads.data.ad_list[1].data.msg).to eq "Hola, mundo!"
405
+ expect(ads.data.ad_list[1].actions.public_view).to eq "https://localbitcoins.com/ad/67890"
406
+ end
407
+
408
+ it 'shows the location information associated with a given latitude and longitude' do
409
+ expect { client.places({:lat=>35, :lon=>100}) }.not_to raise_error
410
+ places = client.places({:lat=>35, :lon=>100})
411
+ expect(places.places[0].location_string).to eq "Hainan, Qinghai, China"
412
+ expect(places.places[0].lon).to eq 100.62
413
+ expect(places.place_count).to eq 1
25
414
  end
26
415
  end
27
- end
416
+ end
@@ -0,0 +1,14 @@
1
+ {
2
+ "data": {
3
+ "username": "bob",
4
+ "trading_partners_count": 9,
5
+ "feedbacks_unconfirmed_count": 2,
6
+ "trade_volume_text": "Less than 25 BTC",
7
+ "has_common_trades": true,
8
+ "confirmed_trade_count_text": "2",
9
+ "blocked_count": 4,
10
+ "feedback_count": 1,
11
+ "url": "https://localbitcoins.com/p/bob/",
12
+ "trusted_count": 3
13
+ }
14
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "data": {
3
+ "message": "Ad added successfully!"
4
+ }
5
+ }
@@ -0,0 +1,103 @@
1
+ {
2
+ "data": {
3
+ "ad_count": 2,
4
+ "ad_list": [
5
+ {
6
+ "data": {
7
+ "require_feedback_score": 90,
8
+ "reference_type": "SHORT",
9
+ "trusted_required": false,
10
+ "currency": "MXN",
11
+ "account_info": "",
12
+ "age_days_coefficient_limit": "4.00",
13
+ "first_time_limit_btc": "2.00",
14
+ "city": "Puerto Vallarta",
15
+ "location_string": "Puerto Vallarta, JAL, Mexico",
16
+ "countrycode": "MX",
17
+ "max_amount": null,
18
+ "lon": -105.22,
19
+ "sms_verification_required": false,
20
+ "require_trade_volume": 0.00,
21
+ "online_provider": "CASH_DEPOSIT",
22
+ "max_amount_available": null,
23
+ "msg": "Contact hours: Mon 09:00-17:00",
24
+ "email": "bob@domain.com",
25
+ "volume_coefficient_btc": "1.50",
26
+ "profile": {
27
+ "username": "Bob",
28
+ "feedback_score": 100,
29
+ "trade_count": "0",
30
+ "last_online": "2014-06-19T16:17:06+00:00",
31
+ "name": "Bob (30+;100%)"
32
+ },
33
+ "bank_name": "Banorte",
34
+ "trade_type": "ONLINE_SELL",
35
+ "ad_id": 12345,
36
+ "temp_price": "8000",
37
+ "min_amount": "500",
38
+ "track_max_amount": true,
39
+ "temp_price_usd": "615",
40
+ "lat": 20.64,
41
+ "price_equation": "localbitcoins_sell_usd",
42
+ "visible": false,
43
+ "created_at": "2014-06-17T15:15:07+00:00",
44
+ "atm_model": null
45
+ },
46
+ "actions": {
47
+ "html_form": "https://localbitcoins.com/ads_edit/12345",
48
+ "public_view": "https://localbitcoins.com/ad/12345",
49
+ "contact_form": "https://localbitcoins.com/api/contact_create/12345/",
50
+ "change_form": "https://localbitcoins.com/api/ad/12345/"
51
+ }
52
+ },
53
+ {
54
+ "data": {
55
+ "require_feedback_score": 85,
56
+ "reference_type": "SHORT",
57
+ "trusted_required": false,
58
+ "currency": "MXN",
59
+ "account_info": "",
60
+ "age_days_coefficient_limit": "4.00",
61
+ "first_time_limit_btc": "2.00",
62
+ "city": "Puerto Vallarta",
63
+ "location_string": "Puerto Vallarta, JAL, Mexico",
64
+ "countrycode": "MX",
65
+ "max_amount": "10000",
66
+ "min_amount": "500",
67
+ "lon": -105.22,
68
+ "sms_verification_required": true,
69
+ "require_trade_volume": 0.00,
70
+ "online_provider": "CASH_DEPOSIT",
71
+ "max_amount_available": null,
72
+ "msg": "Contact hours: Mon 09:00-17:00\n\nMeeting preferences: Starbucks\n",
73
+ "email": "bob@domain.com",
74
+ "volume_coefficient_btc": "1.50",
75
+ "profile": {
76
+ "username": "Bob",
77
+ "feedback_score": 100,
78
+ "trade_count": "0",
79
+ "last_online": "2014-06-19T16:17:06+00:00",
80
+ "name": "Bob (30+;100%)"
81
+ },
82
+ "bank_name": "",
83
+ "trade_type": "LOCAL_SELL",
84
+ "ad_id": 123456,
85
+ "temp_price": "9200",
86
+ "track_max_amount": true,
87
+ "temp_price_usd": "707",
88
+ "lat": 20.64,
89
+ "price_equation": "localbitcoins_sell_usd*1.15",
90
+ "visible": true,
91
+ "created_at": "2014-06-17T15:15:07+00:00",
92
+ "atm_model": null
93
+ },
94
+ "actions": {
95
+ "html_form": "https://localbitcoins.com/ads_edit/123456",
96
+ "public_view": "https://localbitcoins.com/ad/123456",
97
+ "contact_form": "https://localbitcoins.com/api/contact_create/123456/",
98
+ "change_form": "https://localbitcoins.com/api/ad/123456/"
99
+ }
100
+ }
101
+ ]
102
+ }
103
+ }
@@ -0,0 +1,55 @@
1
+ {
2
+ "data": {
3
+ "ad_count": 1,
4
+ "ad_list": [
5
+ {
6
+ "data": {
7
+ "require_feedback_score": 90,
8
+ "reference_type": "SHORT",
9
+ "trusted_required": false,
10
+ "currency": "MXN",
11
+ "account_info": "",
12
+ "age_days_coefficient_limit": "4.00",
13
+ "first_time_limit_btc": "2.00",
14
+ "city": "Puerto Vallarta",
15
+ "location_string": "Puerto Vallarta, JAL, Mexico",
16
+ "countrycode": "MX",
17
+ "max_amount": null,
18
+ "lon": -105.22,
19
+ "sms_verification_required": false,
20
+ "require_trade_volume": 0.00,
21
+ "online_provider": "CASH_DEPOSIT",
22
+ "max_amount_available": null,
23
+ "msg": "Contact hours: Mon 09:00-17:00",
24
+ "email": "bob@domain.com",
25
+ "volume_coefficient_btc": "1.50",
26
+ "profile": {
27
+ "username": "Bob",
28
+ "feedback_score": 100,
29
+ "trade_count": "0",
30
+ "last_online": "2014-06-19T16:17:06+00:00",
31
+ "name": "Bob (30+;100%)"
32
+ },
33
+ "bank_name": "Banorte",
34
+ "trade_type": "ONLINE_SELL",
35
+ "ad_id": 12345,
36
+ "temp_price": "8000",
37
+ "min_amount": "500",
38
+ "track_max_amount": true,
39
+ "temp_price_usd": "615",
40
+ "lat": 20.64,
41
+ "price_equation": "localbitcoins_sell_usd",
42
+ "visible": false,
43
+ "created_at": "2014-06-17T15:15:07+00:00",
44
+ "atm_model": null
45
+ },
46
+ "actions": {
47
+ "html_form": "https://localbitcoins.com/ads_edit/12345",
48
+ "public_view": "https://localbitcoins.com/ad/12345",
49
+ "contact_form": "https://localbitcoins.com/api/contact_create/12345/",
50
+ "change_form": "https://localbitcoins.com/api/ad/12345/"
51
+ }
52
+ }
53
+ ]
54
+ }
55
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "data": {
3
+ "message": "Ad changed successfully!"
4
+ }
5
+ }