openname 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0ff21c569840d76a58bb158b88643067ecde030
4
+ data.tar.gz: ba50050face0f3f78cc4a31984ea51344aa3061c
5
+ SHA512:
6
+ metadata.gz: 04ad91168836900329aa8ee19b1860379c18d1ead0028d3595efce128e800c44dbf6577bc0ef9f518733942da96cf2593386ba2745281991217c397ca00d1eda
7
+ data.tar.gz: ad57b925778d880051987f39cc041563a28b475bb3e22bbfadc52d05198b63cd992826819a90deb52db0895587e4c1db1359e6f906860dfe8880585c31dcaf23
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in openname.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Appartisan Limited
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Openname
2
+
3
+ A ruby library for the Openname distributed identity & naming system
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'openname'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install openname
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ require "openname"
23
+ user = Openname.get("larry")
24
+
25
+ larrys_bitcoin_address = user.bitcoin_address
26
+ larrys_website = user.website
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,155 @@
1
+ require "openname/version"
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+
6
+ ##
7
+ # A toolkit for the Openname distributed identity & naming system
8
+ module Openname
9
+ DEFAULT_ENDPOINT = "https://www.onename.io"
10
+ SCHEMA_VERSION = "0.2"
11
+ USERAGENT = "openname-ruby #{VERSION}"
12
+
13
+ # https://github.com/openname/openname-specifications#usernames
14
+ OPENNAME_REGEX = /^[a-z0-9_]{1,60}$/
15
+
16
+ @@endpoint = nil
17
+
18
+ ##
19
+ # Current endpoint used by the library
20
+ def self.endpoint
21
+ if @@endpoint.nil?
22
+ return DEFAULT_ENDPOINT
23
+ else
24
+ return @@endpoint
25
+ end
26
+ end
27
+
28
+ ##
29
+ # Set endpoint to +url+
30
+ # if +url+ is +nil+, +DEFAULT_ENDPOINT+ is used as the endpoint
31
+ def self.endpoint=(url)
32
+ @@endpoint = url
33
+ end
34
+
35
+ ##
36
+ # Check if the given +openname+ is in proper format
37
+ # Does not downcase input
38
+ def self.valid?(openname)
39
+ Openname::ONENAME_REGEX.match(openname).nil? ? false : true
40
+ end
41
+
42
+ ##
43
+ # Retrieve JSON data stored in Openname record
44
+ def self.get_json(openname)
45
+ raise ArgumentError.new("#{openname} is not a valid Openname") if !self.valid?(openname)
46
+ uri = URI(self.endpoint + "/#{openname.downcase}.json")
47
+ http = Net::HTTP.new(uri.host,uri.port)
48
+ http.use_ssl = uri.scheme == "https" ? true : false
49
+ req = Net::HTTP::Get.new(uri.path, {'User-Agent' => USERAGENT})
50
+ 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
54
+ error = JSON.parse(res.body)
55
+ raise RuntimeError.new("Openname endpoint returned error: #{error["error"]}")
56
+ end
57
+ json = JSON.parse(res.body)
58
+
59
+ end
60
+
61
+ ##
62
+ # Return a +User+ representing the given openname
63
+ def self.get(openname)
64
+ User.from_json(self.get_json(openname),openname)
65
+ end
66
+
67
+
68
+ class User
69
+ def self.from_json(json,openname)
70
+ User.new(json,openname)
71
+ end
72
+
73
+ attr_reader :openname
74
+ attr_reader :name_formatted
75
+ attr_reader :avatar_url
76
+ attr_reader :cover_url
77
+ attr_reader :location_formatted
78
+ attr_reader :website
79
+ attr_reader :bio
80
+ attr_reader :github_username
81
+ attr_reader :facebook_username
82
+ attr_reader :twitter_username
83
+ attr_reader :linkedin_username
84
+ attr_reader :bitcoin_address
85
+ attr_reader :bitmessage_address
86
+ attr_reader :bitcoinotc_username
87
+ attr_reader :pgp_fingerprint
88
+ attr_reader :pgp_url
89
+ attr_reader :orgs
90
+ attr_reader :schema_version
91
+
92
+
93
+ def initialize(json,openname)
94
+ @openname = openname
95
+ @name_formatted = json["name"]["formatted"] if json["name"]
96
+ @avatar_url = json["avatar"]["url"] if json["avatar"]
97
+ @cover_url = json["cover"]["url"] if json["cover"]
98
+ @location_formatted = json["location"]["formatted"] if json["location"]
99
+ @website = json["website"]
100
+ @bio = json["bio"]
101
+ @github_username = json["github"]["username"] if json["github"]
102
+ @facebook_username = json["facebook"]["username"] if json["facebook"]
103
+ @twitter_username = json["twitter"]["username"] if json["twitter"]
104
+ @linkedin_username = json["linkedin"]["username"] if json["linkedin"]
105
+ @bitcoin_address = json["bitcoin"]["address"] if json["bitcoin"]
106
+ @bitmessage_address = json["bitmessage"]["username"] if json["bitmessage"]
107
+ @bitcoinotc_username = json["bitcoinotc"]["username"] if json["bitcoinotc"]
108
+ @pgp_fingerprint = json["pgp"]["fingerprint"] if json["pgp"]
109
+ @pgp_url = json["pgp"]["url"] if json["url"]
110
+ @schema_version = json["v"]
111
+ @orgs = parse_orgs(json["orgs"])
112
+ end
113
+
114
+ protected
115
+
116
+ def parse_orgs(orgs_json)
117
+ orgs = Array.new
118
+ if orgs_json
119
+ for org_json in orgs_json
120
+ orgs << Org.new(org_json)
121
+ end
122
+ end
123
+ orgs
124
+ end
125
+
126
+ end
127
+
128
+ class Org
129
+ def self.from_json(json)
130
+ Org.new(json)
131
+ end
132
+
133
+ attr_reader :url
134
+ attr_reader :relationship
135
+ attr_reader :name
136
+
137
+
138
+ def initialize(json)
139
+ @url = json["url"] if json["url"]
140
+ @relationship = json["relationship"] if json["relationship"]
141
+ @name = json["name"] if json["name"]
142
+ end
143
+
144
+
145
+ end
146
+
147
+ protected
148
+
149
+ def self.check_schema_version(json_result)
150
+ if json_result["v"] != SCHEMA_VERSION
151
+ warn "Openname gem only supports Openname schema version #{SCHEMA_VERSION}"
152
+ end
153
+ end
154
+
155
+ end
@@ -0,0 +1,3 @@
1
+ module Openname
2
+ VERSION = "0.3"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'openname/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "openname"
8
+ spec.version = Openname::VERSION
9
+ spec.authors = ["Larry Salibra"]
10
+ spec.email = ["larry@pay4bugs.com"]
11
+ spec.description = "Ruby library for the Openname distributed identity & naming system"
12
+ spec.summary = "Library for Openname"
13
+ spec.homepage = "https://github.com/pay4bugs/openname-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "vcr"
26
+ end
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://www.onename.io/larry.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - onename-ruby 0.1
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json
23
+ Date:
24
+ - Sun, 06 Apr 2014 14:00:02 GMT
25
+ Server:
26
+ - gunicorn/18.0
27
+ Strict-Transport-Security:
28
+ - max-age=31536000
29
+ Content-Length:
30
+ - '909'
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n \"bitcoin\": {\n \"address\": \"143xFrxppUD9oQE7mGvQFe23h814YorMBs\"\n
36
+ \ }, \n \"avatar\": {\n \"url\": \"http://www.larrysalibra.com/images/custom/larry.png\"\n
37
+ \ }, \n \"facebook\": {\n \"username\": \"larry.salibra\"\n }, \n \"cover\":
38
+ {\n \"url\": \"http://www.larrysalibra.com/images/custom/home_bg.png\"\n
39
+ \ }, \n \"instagram\": {\n \"username\": \"larrysalibra\"\n }, \n \"location\":
40
+ {\n \"formatted\": \"Hong Kong\"\n }, \n \"linkedin\": {\n \"url\":
41
+ \"http://www.linkedin.com/in/larrysalibra\"\n }, \n \"github\": {\n \"username\":
42
+ \"larrysalibra\"\n }, \n \"v\": \"0.2\", \n \"twitter\": {\n \"username\":
43
+ \"larrysalibra\"\n }, \n \"bio\": \"Founder/CEO Pay4Bugs\", \n \"website\":
44
+ \"http://www.larrysalibra.com\", \n \"angellist\": {\n \"username\": \"larry-salibra\"\n
45
+ \ }, \n \"pgp\": {\n \"url\": \"https://keybase.io/larry/key.asc\", \n
46
+ \ \"fingerprint\": \"B516CB7A08819697B25E4694DE3B5425164C4849\"\n }, \n
47
+ \ \"name\": {\n \"formatted\": \"Larry Salibra\"\n }\n}"
48
+ http_version:
49
+ recorded_at: Sun, 06 Apr 2014 14:00:02 GMT
50
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Openname, :vcr => { :cassette_name => "openname" } do
4
+
5
+
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
21
+
22
+ context "we've retrieved an openname user" do
23
+ before :each do
24
+ @user = Openname.get("larry")
25
+ end
26
+
27
+ it "should have a openname" do
28
+ @user.openname.should == "larry"
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'openname'
2
+ require 'vcr'
3
+
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
6
+ c.hook_into :webmock
7
+ c.configure_rspec_metadata!
8
+ end
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openname
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
+ platform: ruby
6
+ authors:
7
+ - Larry Salibra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby library for the Openname distributed identity & naming system
84
+ email:
85
+ - larry@pay4bugs.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/openname.rb
96
+ - lib/openname/version.rb
97
+ - openname.gemspec
98
+ - spec/fixtures/cassettes/openname.yml
99
+ - spec/lib/onename_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/pay4bugs/openname-ruby
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Library for Openname
125
+ test_files:
126
+ - spec/fixtures/cassettes/openname.yml
127
+ - spec/lib/onename_spec.rb
128
+ - spec/spec_helper.rb