openname 0.3 → 0.4

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: f0ff21c569840d76a58bb158b88643067ecde030
4
- data.tar.gz: ba50050face0f3f78cc4a31984ea51344aa3061c
3
+ metadata.gz: 12fa57d0eddaa6b5e7024a8020060c07c85207ee
4
+ data.tar.gz: 8ecea83221d00a389cd5285e82438c4ad140dcb0
5
5
  SHA512:
6
- metadata.gz: 04ad91168836900329aa8ee19b1860379c18d1ead0028d3595efce128e800c44dbf6577bc0ef9f518733942da96cf2593386ba2745281991217c397ca00d1eda
7
- data.tar.gz: ad57b925778d880051987f39cc041563a28b475bb3e22bbfadc52d05198b63cd992826819a90deb52db0895587e4c1db1359e6f906860dfe8880585c31dcaf23
6
+ metadata.gz: 209ba518efcf73b42c5eae62256518d63f2a365d638f268ed59dd05b7a49235e356f57ed4198fdcc4e4a50848e7798c1c3c5af8aa4954bb4b04368aa7e786485
7
+ data.tar.gz: 050dacec96225c9016d045ce8d87e3b939b4b3f366015d2c197402f83f035357305c62ff0750a213a69502dfa01d1601644d4de5857f6334b9720c64cd79748f
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in openname.gemspec
4
4
  gemspec
5
+ gem 'bitcoin-ruby', git: 'https://github.com/lian/bitcoin-ruby', branch: 'master', require: 'bitcoin'
6
+
data/lib/openname.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "openname/version"
2
2
  require 'net/http'
3
3
  require 'json'
4
+ require 'bitcoin'
4
5
 
5
6
 
6
7
  ##
@@ -36,7 +37,7 @@ module Openname
36
37
  # Check if the given +openname+ is in proper format
37
38
  # Does not downcase input
38
39
  def self.valid?(openname)
39
- Openname::ONENAME_REGEX.match(openname).nil? ? false : true
40
+ Openname::OPENNAME_REGEX.match(openname).nil? ? false : true
40
41
  end
41
42
 
42
43
  ##
@@ -48,13 +49,13 @@ module Openname
48
49
  http.use_ssl = uri.scheme == "https" ? true : false
49
50
  req = Net::HTTP::Get.new(uri.path, {'User-Agent' => USERAGENT})
50
51
  res = http.request(req)
51
- case res.code
52
- when 404 then raise NameError.new("User with Openname \"#{openname}\" does not exist")
53
- when res.code != 200 then
52
+ case res.code.to_s
53
+ when "404" then raise NameError.new("User with Openname \"#{openname}\" does not exist")
54
+ when "200" then return JSON.parse(res.body)
55
+ else
54
56
  error = JSON.parse(res.body)
55
57
  raise RuntimeError.new("Openname endpoint returned error: #{error["error"]}")
56
58
  end
57
- json = JSON.parse(res.body)
58
59
 
59
60
  end
60
61
 
@@ -64,6 +65,16 @@ module Openname
64
65
  User.from_json(self.get_json(openname),openname)
65
66
  end
66
67
 
68
+ ##
69
+ # Takes either a bitcoin address or a openname
70
+ # Returns the bitcoin address associated with the openname or passes through address provided
71
+ def self.get_bitcoin_address(openname_or_address)
72
+ return openname_or_address if Bitcoin.valid_address?(openname_or_address)
73
+ raise ArgumentError.new("#{openname_or_address} is not a valid Openname or Bitcoin address") if !self.valid?(openname_or_address)
74
+ user = get(openname_or_address)
75
+ raise NameError.new("Openname user #{openname_or_address} does not have a Bitcoin address") if !Bitcoin.valid_address?(user.bitcoin_address)
76
+ return user.bitcoin_address
77
+ end
67
78
 
68
79
  class User
69
80
  def self.from_json(json,openname)
@@ -1,3 +1,3 @@
1
1
  module Openname
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
data/openname.gemspec CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "webmock"
25
25
  spec.add_development_dependency "vcr"
26
+
27
+ spec.add_runtime_dependency 'bitcoin-ruby'
26
28
  end
@@ -47,4 +47,76 @@ http_interactions:
47
47
  \ \"name\": {\n \"formatted\": \"Larry Salibra\"\n }\n}"
48
48
  http_version:
49
49
  recorded_at: Sun, 06 Apr 2014 14:00:02 GMT
50
+ - request:
51
+ method: get
52
+ uri: https://www.onename.io/bitcoinhater.json
53
+ body:
54
+ encoding: US-ASCII
55
+ string: ''
56
+ headers:
57
+ User-Agent:
58
+ - onename-ruby 0.1
59
+ Accept-Encoding:
60
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
61
+ Accept:
62
+ - '*/*'
63
+ response:
64
+ status:
65
+ code: 200
66
+ message: OK
67
+ headers:
68
+ Content-Type:
69
+ - application/json
70
+ Date:
71
+ - Sun, 06 Apr 2014 14:00:02 GMT
72
+ Server:
73
+ - gunicorn/18.0
74
+ Strict-Transport-Security:
75
+ - max-age=31536000
76
+ Content-Length:
77
+ - '909'
78
+ Connection:
79
+ - keep-alive
80
+ body:
81
+ encoding: UTF-8
82
+ string: "{\n \n \"avatar\": {\n \"url\": \"http://www.example.com/pic.png\"\n
83
+ \ }, \n
84
+ \ \"name\": {\n \"formatted\": \"Bitcoin Hater\"\n }\n}"
85
+ http_version:
86
+ recorded_at: Sun, 06 Apr 2014 14:00:02 GMT
87
+ - request:
88
+ method: get
89
+ uri: https://www.onename.io/nothere.json
90
+ body:
91
+ encoding: US-ASCII
92
+ string: ''
93
+ headers:
94
+ User-Agent:
95
+ - onename-ruby 0.1
96
+ Accept-Encoding:
97
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
98
+ Accept:
99
+ - '*/*'
100
+ response:
101
+ status:
102
+ code: 404
103
+ message: NOT FOUND
104
+ headers:
105
+ Content-Type:
106
+ - application/json
107
+ Date:
108
+ - Sun, 06 Apr 2014 14:00:02 GMT
109
+ Server:
110
+ - gunicorn/18.0
111
+ Strict-Transport-Security:
112
+ - max-age=31536000
113
+ Content-Length:
114
+ - '909'
115
+ Connection:
116
+ - keep-alive
117
+ body:
118
+ encoding: UTF-8
119
+ string: ""
120
+ http_version:
121
+ recorded_at: Sun, 06 Apr 2014 14:00:02 GMT
50
122
  recorded_with: VCR 2.9.0
@@ -1,23 +1,30 @@
1
1
  require 'spec_helper'
2
+ require 'bitcoin'
2
3
 
3
4
  describe Openname, :vcr => { :cassette_name => "openname" } do
4
5
 
5
6
 
6
- it "should have a default endpoint" do
7
- Openname.endpoint.should == "https://www.onename.io"
8
- end
9
-
10
- it "should allow setting a different endpoint and returning to default" do
11
- Openname.endpoint = "https://www.example.com"
12
- Openname.endpoint.should == "https://www.example.com"
13
- Openname.endpoint = nil
14
- Openname.endpoint.should == "https://www.onename.io"
15
- end
16
-
17
- it "should retrieve openname user" do
18
- user = Openname.get("larry")
19
- user.is_a?(Openname::User).should == true
20
- end
7
+ it "should have a default endpoint" do
8
+ Openname.endpoint.should == "https://www.onename.io"
9
+ end
10
+
11
+ it "should allow setting a different endpoint and returning to default" do
12
+ Openname.endpoint = "https://www.example.com"
13
+ Openname.endpoint.should == "https://www.example.com"
14
+ Openname.endpoint = nil
15
+ Openname.endpoint.should == "https://www.onename.io"
16
+ end
17
+
18
+ it "should retrieve openname user" do
19
+ user = Openname.get("larry")
20
+ user.is_a?(Openname::User).should == true
21
+ end
22
+
23
+ it "should give error if openname user does not exist" do
24
+ expect {
25
+ user = Openname.get("nothere")
26
+ }.to raise_error(NameError)
27
+ end
21
28
 
22
29
  context "we've retrieved an openname user" do
23
30
  before :each do
@@ -28,5 +35,34 @@ describe Openname, :vcr => { :cassette_name => "openname" } do
28
35
  @user.openname.should == "larry"
29
36
  end
30
37
 
38
+ it "should have a bitcoin address" do
39
+ address = @user.bitcoin_address
40
+ Bitcoin.valid_address?(address).should == true
41
+ end
42
+
31
43
  end
44
+
45
+ context "retrieving Bitcoin addreses" do
46
+ it "should retrieve a Bitcoin address" do
47
+ address = Openname.get_bitcoin_address("larry")
48
+ Bitcoin.valid_address?(address).should == true
49
+
50
+ address = Openname.get_bitcoin_address("143xFrxppUD9oQE7mGvQFe23h814YorMBs")
51
+ Bitcoin.valid_address?(address).should == true
52
+ end
53
+
54
+ it "should raise an error when retrieving poorly formed Bitcoin address" do
55
+ expect {
56
+ address = Openname.get_bitcoin_address("143xFrxpp")
57
+ }.to raise_error(ArgumentError)
58
+
59
+ end
60
+
61
+ it "should raise an error when user has no Bitcoin address" do
62
+ expect {
63
+ address = Openname.get_bitcoin_address("bitcoinhater")
64
+ }.to raise_error(NameError)
65
+
66
+ end
67
+ end
32
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openname
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Salibra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bitcoin-ruby
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Ruby library for the Openname distributed identity & naming system
84
98
  email:
85
99
  - larry@pay4bugs.com