localbitcoins 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e26538ea5d0e612baff16fa2f93a3a5a7230e46
4
- data.tar.gz: c1f6c5e4f42c2d26c9ad5b100f7bfa2ad5ca5432
3
+ metadata.gz: f32b2111b3e627e2cdadc083e665f9d9af54d4c8
4
+ data.tar.gz: aaa3523f0a7c6cbb944d6047f361df38261bbbb0
5
5
  SHA512:
6
- metadata.gz: c125d972fab3ba0702599ddf27d25abee1deafc2b22dbc7206f935ae6528efb92cc75e1628ba93ab5afaf2f0ae241e9595a3029f7d423697d091dd9c6554a3fd
7
- data.tar.gz: db8add4569e1b29a65d2010c59eb7f02041c10ecba0d846eeba33d73624e5254771a6c00176243f77e151134e6fcc73811507554eb6fb03ac9854d16e58aa0e6
6
+ metadata.gz: f1b20d3836f2eb810bbccf0eca763dd88ee929bd456bbd25e95386b76c00fac5cdb4bb94a8149a4916f31ae47cea52de87623bf8b46f88433cabc4879d1bdc6d
7
+ data.tar.gz: d4e2c991028a547274adeb72c636fd1f764fcfc312f28f57a82a21e0fc07722bcf53ace2750f50a29ac5257b0f4f01323b21c482a5ce72f62eb885ad586cb656
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- localbitcoins (0.0.2)
4
+ localbitcoins (0.0.4)
5
5
  activesupport (~> 3)
6
6
  hashie (~> 2.0.2)
7
7
  json (~> 1.8.0)
8
- oauth (~> 0.4)
8
+ oauth2 (~> 0.9.2)
9
9
  rest-client (~> 1.6)
10
10
 
11
11
  GEM
@@ -18,12 +18,26 @@ GEM
18
18
  crack (0.4.0)
19
19
  safe_yaml (~> 0.9.0)
20
20
  diff-lcs (1.2.4)
21
+ faraday (0.8.7)
22
+ multipart-post (~> 1.1)
21
23
  hashie (2.0.5)
24
+ httpauth (0.2.0)
22
25
  i18n (0.6.1)
23
26
  json (1.8.0)
27
+ jwt (0.1.8)
28
+ multi_json (>= 1.5)
24
29
  mime-types (1.23)
25
30
  multi_json (1.7.7)
26
- oauth (0.4.7)
31
+ multi_xml (0.5.4)
32
+ multipart-post (1.2.0)
33
+ oauth2 (0.9.2)
34
+ faraday (~> 0.8)
35
+ httpauth (~> 0.2)
36
+ jwt (~> 0.1.4)
37
+ multi_json (~> 1.0)
38
+ multi_xml (~> 0.5)
39
+ rack (~> 1.2)
40
+ rack (1.5.2)
27
41
  rest-client (1.6.7)
28
42
  mime-types (>= 1.16)
29
43
  rspec (2.14.1)
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
- # LocalBitcoins API Gem 0.0.2
1
+ # LocalBitcoins API Gem 0.0.3
2
2
 
3
3
  This gem provides a simple, extensible Ruby wrapper to access the [LocalBitcoins API](https://localbitcoins.com/api-docs/).
4
4
 
5
- THIS IS A WORK IN PROGRESS AND DOES NOT YET HAVE A TEST SUITE. DO NOT USE THIS IN PRODUCTION APPLICATIONS UNTIL THE TEST SUITE HAS BEEN WRITTEN. THANKS!
6
-
7
5
  ## Installation
8
6
 
9
7
  Install the gem:
@@ -64,7 +62,7 @@ You can get a list of the token owner's releaseable escrows through the OAuth cl
64
62
  ``` ruby
65
63
  escrows = client.escrows
66
64
 
67
- escrows.each do |e|
65
+ escrows.escrow_list.each do |e|
68
66
  e.data.created_at # => UTC datetime escrow was created at
69
67
  e.data.buyer_username # => username of the buyer
70
68
  e.data.reference_code # => reference code for the escrow
@@ -89,7 +87,7 @@ You can get a list of the token owner's ads with the following method:
89
87
  ``` ruby
90
88
  ads = client.ads
91
89
 
92
- ads.each do |a|
90
+ ads.ad_list.each do |a|
93
91
  a.data.visible # => boolean value of the ad's visibility
94
92
  a.data.email # => valid e-mail string or null
95
93
  a.data.location_string # => human-readable location
@@ -4,7 +4,7 @@ module LocalBitcoins
4
4
  #
5
5
  def escrows()
6
6
  data = oauth_request(:get, '/api/escrows')
7
- Hashie::Mash.new(data['escrow_list'])
7
+ Hashie::Mash.new(data)
8
8
  end
9
9
 
10
10
  # Release an escrow
@@ -8,13 +8,12 @@ module LocalBitcoins
8
8
  include LocalBitcoins::Escrows
9
9
  include LocalBitcoins::Ads
10
10
 
11
- attr_reader :oauth_token
11
+ attr_reader :oauth_client, :access_token
12
12
 
13
13
  # Initialize a LocalBitcoins::Client instance
14
14
  #
15
- # All API calls to LocalBitcoins require an OAuth token, so you
16
- # need to include one when you initialize the client.
17
- #
15
+ # options[:client_id]
16
+ # options[:client_secret]
18
17
  # options[:oauth_token]
19
18
  #
20
19
  def initialize(options={})
@@ -22,7 +21,18 @@ module LocalBitcoins
22
21
  raise ArgumentError, "Options hash required."
23
22
  end
24
23
 
25
- @oauth_token = options[:oauth_token]
24
+ @oauth_client = OAuth2::Client.new(
25
+ options[:client_id],
26
+ options[:client_secret],
27
+ authorize_url: "/oauth2/authorize",
28
+ token_url: "/oauth2/access_token",
29
+ site: "https://www.localbitcoins.com"
30
+ )
31
+
32
+ @access_token = OAuth2::AccessToken.new(
33
+ oauth_client,
34
+ options[:oauth_token]
35
+ )
26
36
  end
27
37
  end
28
38
  end
@@ -2,9 +2,11 @@ require 'rest-client'
2
2
  require 'active_support/core_ext'
3
3
  require 'json'
4
4
  require 'hashie'
5
+ require 'oauth2'
5
6
 
6
7
  module LocalBitcoins
7
8
  module Request
9
+ API_URL = "https://www.localbitcoins.com"
8
10
 
9
11
  protected
10
12
 
@@ -16,9 +18,9 @@ module LocalBitcoins
16
18
  # params - Parameters hash
17
19
  #
18
20
  def oauth_request(http_method, path, params={})
19
- raise 'OAuth access token required!' unless @oauth_token
21
+ raise 'OAuth access token required!' unless @access_token
20
22
  params.merge!('Accept'=>'application/json')
21
- resp = @oauth_token.request(http_method, path, params)
23
+ resp = @access_token.request(http_method, path, params)
22
24
 
23
25
  case resp
24
26
  when Net::HTTPUnauthorized
@@ -1,5 +1,5 @@
1
1
  module LocalBitcoins
2
2
  unless defined?(LocalBitcoins::VERSION)
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_runtime_dependency 'rest-client', '~> 1.6'
19
19
  s.add_runtime_dependency 'hashie', '~> 2.0.2'
20
20
  s.add_runtime_dependency 'activesupport', '~> 3'
21
- s.add_runtime_dependency 'oauth', '~> 0.4'
21
+ s.add_runtime_dependency 'oauth2', '~> 0.9.2'
22
22
 
23
23
  s.files = `git ls-files`.split("\n")
24
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/spec/client_spec.rb CHANGED
@@ -1,22 +1,27 @@
1
1
  require 'spec_helper'
2
- require 'oauth'
2
+ require 'oauth2'
3
3
 
4
4
  describe 'Client' do
5
- describe '#escrows' do
6
- let(:consumer) { OAuth::Consumer.new('CLIENT_ID', 'CLIENT_SECRET', site: 'https://www.localbitcoins.com') }
7
- let(:token) { OAuth::AccessToken.new(consumer, 'ACCESS_TOKEN', 'ACCESS_SECRET') }
5
+ let(:client) { LocalBitcoins::Client.new(
6
+ client_id: 'CLIENT_ID',
7
+ client_secret: 'CLIENT_SECRET',
8
+ oauth_token: 'ACCESS_TOKEN'
9
+ )}
8
10
 
11
+ describe "#escrows" do
9
12
  before do
10
- stub_request(:get, "https://www.localbitcoins.com/oauth2/access_token").
11
- to_return(status: 200, body: fixture('oauth_response.json'), headers: {})
13
+ stub_get('/api/escrows/', 'escrows.json')
12
14
  end
13
15
 
14
16
  it 'returns escrows owner of the access token can release' do
15
- client = LocalBitcoins::Client.new(oauth_token: token)
16
-
17
- escrows = client.escrows
17
+ expect { client.escrows }.not_to raise_error
18
18
 
19
+ escrows = client.escrows
19
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/"
20
25
  end
21
26
  end
22
27
  end
@@ -1,10 +1,10 @@
1
- {
2
- "escrow_list": [
1
+ { "escrow_list":
2
+ [
3
3
  {
4
4
  "data": {
5
5
  "created_at": "2013-06-20T15:23:01.61",
6
6
  "buyer_username": "alice",
7
- "reference_code": "123",
7
+ "reference_code": "123"
8
8
  },
9
9
  "actions": {
10
10
  "release_url": "/api/escrow_release/1/"
@@ -14,7 +14,7 @@
14
14
  "data": {
15
15
  "created_at": "2013-06-21T16:20:13.04",
16
16
  "buyer_username": "bob",
17
- "reference_code": "456",
17
+ "reference_code": "456"
18
18
  },
19
19
  "actions": {
20
20
  "release_url": "/api/escrow_release/2/"
data/spec/spec_helper.rb CHANGED
@@ -10,15 +10,21 @@ RSpec.configure do |config|
10
10
  end
11
11
 
12
12
  def stub_get(path, fixture_name)
13
- stub_request(:get, api_url(path)).
14
- with(headers: {
15
- 'Accept'=>'application/json'
16
- }).
17
- to_return(
18
- status: 200,
19
- body: fixture(fixture_name),
20
- headers: {}
21
- )
13
+ stub_request(:get, "https://www.localbitcoins.com/api/escrows").
14
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer ACCESS_TOKEN', 'User-Agent'=>'Faraday v0.8.7'}).
15
+ to_return(:status => 200, :body => fixture(fixture_name), :headers => {})
16
+ # stub_request(:get, api_url(path)).
17
+ # with(
18
+ # headers: {
19
+ # 'Accept' => 'application/json',
20
+ # 'Authorization' => 'Bearer ACCESS_TOKEN',
21
+ # 'User-Agent' => 'Faraday v0.8.7'
22
+ # }).
23
+ # to_return(
24
+ # status: 200,
25
+ # body: fixture(fixture_name),
26
+ # headers: {}
27
+ # )
22
28
  end
23
29
 
24
30
  def stub_post(path, fixture_name)
@@ -46,5 +52,5 @@ def fixture(file)
46
52
  end
47
53
 
48
54
  def api_url(path)
49
- "https://www.localbitcoins.com#{path}"
55
+ "#{LocalBitcoins::Request::API_URL}#{path}"
50
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localbitcoins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Shutt
@@ -95,19 +95,19 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3'
97
97
  - !ruby/object:Gem::Dependency
98
- name: oauth
98
+ name: oauth2
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ~>
102
102
  - !ruby/object:Gem::Version
103
- version: '0.4'
103
+ version: 0.9.2
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
- version: '0.4'
110
+ version: 0.9.2
111
111
  description: Ruby wrapper for the LocalBitcoins API
112
112
  email:
113
113
  - john.d.shutt@gmail.com