openname 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/openname.rb +16 -5
- data/lib/openname/version.rb +1 -1
- data/openname.gemspec +2 -0
- data/spec/fixtures/cassettes/openname.yml +72 -0
- data/spec/lib/onename_spec.rb +51 -15
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12fa57d0eddaa6b5e7024a8020060c07c85207ee
|
4
|
+
data.tar.gz: 8ecea83221d00a389cd5285e82438c4ad140dcb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 209ba518efcf73b42c5eae62256518d63f2a365d638f268ed59dd05b7a49235e356f57ed4198fdcc4e4a50848e7798c1c3c5af8aa4954bb4b04368aa7e786485
|
7
|
+
data.tar.gz: 050dacec96225c9016d045ce8d87e3b939b4b3f366015d2c197402f83f035357305c62ff0750a213a69502dfa01d1601644d4de5857f6334b9720c64cd79748f
|
data/Gemfile
CHANGED
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::
|
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
|
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)
|
data/lib/openname/version.rb
CHANGED
data/openname.gemspec
CHANGED
@@ -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
|
data/spec/lib/onename_spec.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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.
|
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-
|
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
|