onename 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18c3c0ad91f44ea48651d449bab5f6d5e6b4bca8
4
+ data.tar.gz: 34f62ee837084a8767b37f79a90c8bb2d23f4bfb
5
+ SHA512:
6
+ metadata.gz: d9d84369ee46c65a399aecbd3992245a95d38ed830779f4e4d678e86d0ddfa1e2929c29a0a5f93f15fea92124e12bd067e986aa07f03b83aa52e4182ac3e2f26
7
+ data.tar.gz: b9ded855f931ce6eb4eead10d78f8b36319a09912fcbf9e5ae21f247e4e6083f41cde5007fd3f795a4b796b9af57a7ee60f3f8ce143b9c0d89d9e3ca4bfdaeec
data/.gitignore ADDED
@@ -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 onename.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Onename
2
+
3
+ A ruby library for the OneName distributed identity system
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'onename'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install onename
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ require "onename"
23
+ user = Onename.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
data/Rakefile ADDED
@@ -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,3 @@
1
+ module Onename
2
+ VERSION = "0.1"
3
+ end
data/lib/onename.rb ADDED
@@ -0,0 +1,155 @@
1
+ require "onename/version"
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+
6
+ ##
7
+ # A toolkit for the OneName distributed identity system
8
+ module Onename
9
+ DEFAULT_ENDPOINT = "https://www.onename.io"
10
+ SCHEMA_VERSION = "0.2"
11
+ USERAGENT = "onename-ruby #{VERSION}"
12
+
13
+ # https://github.com/onenameio/onename#usernames
14
+ ONENAME_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 +onename+ is in proper format
37
+ # Does not downcase input
38
+ def self.valid?(onename)
39
+ Onename::ONENAME_REGEX.match(onename).nil? ? false : true
40
+ end
41
+
42
+ ##
43
+ # Retrieve JSON data stored in OneName record
44
+ def self.get_json(onename)
45
+
46
+ uri = URI(self.endpoint + "/#{onename.downcase}.json")
47
+ https = Net::HTTP.new(uri.host,uri.port)
48
+ https.use_ssl = true
49
+ req = Net::HTTP::Get.new(uri.path, {'User-Agent' => USERAGENT})
50
+ res = https.request(req)
51
+ case res.code
52
+ when 404 then raise NameError.new("User with OneName \"#{onename}\" does not exist")
53
+ when res.code != 200 then
54
+ error = JSON.parse(res.body)
55
+ raise RuntimeError.new("OneName 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 onename
63
+ def self.get(onename)
64
+ User.from_json(self.get_json(onename),onename)
65
+ end
66
+
67
+
68
+ class User
69
+ def self.from_json(json,onename)
70
+ User.new(json,onename)
71
+ end
72
+
73
+ attr_reader :onename
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,onename)
94
+ @onename = onename
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 "Onename gem only supports OneName schema version #{SCHEMA_VERSION}"
152
+ end
153
+ end
154
+
155
+ end
data/onename.gemspec ADDED
@@ -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 'onename/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "onename"
8
+ spec.version = Onename::VERSION
9
+ spec.authors = ["Larry Salibra"]
10
+ spec.email = ["larry@pay4bugs.com"]
11
+ spec.description = "Ruby library for the OneName distributed identity system"
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/pay4bugs/onename-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 Onename, :vcr => { :cassette_name => "onename" } do
4
+
5
+
6
+ it "should have a default endpoint" do
7
+ Onename.endpoint.should == "https://www.onename.io"
8
+ end
9
+
10
+ it "should allow setting a different endpoint and returning to default" do
11
+ Onename.endpoint = "https://www.example.com"
12
+ Onename.endpoint.should == "https://www.example.com"
13
+ Onename.endpoint = nil
14
+ Onename.endpoint.should == "https://www.onename.io"
15
+ end
16
+
17
+ it "should retrieve onename user" do
18
+ user = Onename.get("larry")
19
+ user.is_a?(Onename::User).should == true
20
+ end
21
+
22
+ context "we've retrieved a onename user" do
23
+ before :each do
24
+ @user = Onename.get("larry")
25
+ end
26
+
27
+ it "should have a onename" do
28
+ @user.onename.should == "larry"
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require 'onename'
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: onename
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Larry Salibra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-06 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 OneName distributed identity 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/onename.rb
96
+ - lib/onename/version.rb
97
+ - onename.gemspec
98
+ - spec/fixtures/cassettes/onename.yml
99
+ - spec/lib/onename_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/pay4bugs/onename-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.1.8
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Ruby library for the OneName distributed identity system
125
+ test_files:
126
+ - spec/fixtures/cassettes/onename.yml
127
+ - spec/lib/onename_spec.rb
128
+ - spec/spec_helper.rb