apihub 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/apihub.rb +6 -8
- data/lib/apihub/base.rb +6 -0
- data/lib/apihub/company.rb +2 -6
- data/lib/apihub/mash.rb +180 -0
- data/lib/apihub/person.rb +2 -6
- data/lib/apihub/resource.rb +64 -0
- data/lib/apihub/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7fcd2e39fb3f5ab4c9b47a7a9d04da231f994ea
|
4
|
+
data.tar.gz: e1652e4f2d388b899629ff272948f7124ac77b36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a5710248e6297795a27b5229c839443046ad598c50e649da888786759e54ed6c0dfeaebdbd056e7d0ca85498a22f16b1eda1581875866281bad17a4c3456045
|
7
|
+
data.tar.gz: 88738052c23d0804d0c49bb0a79366cd70e80d9ab8480b27999f0ce1763adf975357548ab261536326b9d10f63595b614e530dc3c1bf89cd79a33bf37f186e27
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
First authorize requests by setting the API key found on your [account's settings page](https://apihub.co/profile).
|
22
22
|
|
23
|
-
APIHub.api_key = ENV['
|
23
|
+
APIHub.api_key = ENV['APIHUB_KEY']
|
24
24
|
|
25
25
|
Then you can lookup people by email address:
|
26
26
|
|
data/lib/apihub.rb
CHANGED
@@ -4,8 +4,8 @@ require 'apihub/version'
|
|
4
4
|
module APIHub
|
5
5
|
def self.api_key=(value)
|
6
6
|
Base.options Base.options.merge(
|
7
|
-
:
|
8
|
-
:
|
7
|
+
auth_type: :bearer,
|
8
|
+
password: value
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
@@ -13,11 +13,9 @@ module APIHub
|
|
13
13
|
self.api_key = value
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
endpoint 'https://api.apihub.co'
|
18
|
-
options :format => :json
|
19
|
-
end
|
20
|
-
|
21
|
-
autoload :Person, 'apihub/person'
|
16
|
+
autoload :Base, 'apihub/base'
|
22
17
|
autoload :Company, 'apihub/company'
|
18
|
+
autoload :Mash, 'apihub/mash'
|
19
|
+
autoload :Person, 'apihub/person'
|
20
|
+
autoload :Resource, 'apihub/resource'
|
23
21
|
end
|
data/lib/apihub/base.rb
ADDED
data/lib/apihub/company.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module APIHub
|
2
2
|
class Company < Base
|
3
|
-
endpoint 'https://company.apihub.co'
|
3
|
+
endpoint 'https://company-stream.apihub.co'
|
4
4
|
path '/v1/companies'
|
5
5
|
|
6
6
|
def self.find(values, options = {})
|
@@ -21,11 +21,7 @@ module APIHub
|
|
21
21
|
raise ArgumentError, 'Invalid values'
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
self.new(pending: true)
|
26
|
-
else
|
27
|
-
self.new(response)
|
28
|
-
end
|
24
|
+
self.new(response)
|
29
25
|
|
30
26
|
rescue Nestful::ResourceNotFound
|
31
27
|
end
|
data/lib/apihub/mash.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
module APIHub
|
2
|
+
class Mash < Hash
|
3
|
+
def self.new(value = nil, *args)
|
4
|
+
if value.respond_to?(:each) &&
|
5
|
+
!value.respond_to?(:each_pair)
|
6
|
+
value.map {|v| super(v) }
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :to_s, :inspect
|
13
|
+
|
14
|
+
def initialize(source_hash = nil, default = nil, &blk)
|
15
|
+
deep_update(source_hash.to_hash) if source_hash
|
16
|
+
default ? super(default) : super(&blk)
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self; alias [] new; end
|
20
|
+
|
21
|
+
def id #:nodoc:
|
22
|
+
self['id']
|
23
|
+
end
|
24
|
+
|
25
|
+
def type #:nodoc:
|
26
|
+
self['type']
|
27
|
+
end
|
28
|
+
|
29
|
+
alias_method :regular_reader, :[]
|
30
|
+
alias_method :regular_writer, :[]=
|
31
|
+
|
32
|
+
# Retrieves an attribute set in the Mash. Will convert
|
33
|
+
# any key passed in to a string before retrieving.
|
34
|
+
def custom_reader(key)
|
35
|
+
value = regular_reader(convert_key(key))
|
36
|
+
yield value if block_given?
|
37
|
+
value
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets an attribute in the Mash. Key will be converted to
|
41
|
+
# a string before it is set, and Hashes will be converted
|
42
|
+
# into Mashes for nesting purposes.
|
43
|
+
def custom_writer(key,value) #:nodoc:
|
44
|
+
regular_writer(convert_key(key), convert_value(value))
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method :[], :custom_reader
|
48
|
+
alias_method :[]=, :custom_writer
|
49
|
+
|
50
|
+
# This is the bang method reader, it will return a new Mash
|
51
|
+
# if there isn't a value already assigned to the key requested.
|
52
|
+
def initializing_reader(key)
|
53
|
+
ck = convert_key(key)
|
54
|
+
regular_writer(ck, self.class.new) unless key?(ck)
|
55
|
+
regular_reader(ck)
|
56
|
+
end
|
57
|
+
|
58
|
+
# This is the under bang method reader, it will return a temporary new Mash
|
59
|
+
# if there isn't a value already assigned to the key requested.
|
60
|
+
def underbang_reader(key)
|
61
|
+
ck = convert_key(key)
|
62
|
+
if key?(ck)
|
63
|
+
regular_reader(ck)
|
64
|
+
else
|
65
|
+
self.class.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def fetch(key, *args)
|
70
|
+
super(convert_key(key), *args)
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete(key)
|
74
|
+
super(convert_key(key))
|
75
|
+
end
|
76
|
+
|
77
|
+
alias_method :regular_dup, :dup
|
78
|
+
# Duplicates the current mash as a new mash.
|
79
|
+
def dup
|
80
|
+
self.class.new(self, self.default)
|
81
|
+
end
|
82
|
+
|
83
|
+
def key?(key)
|
84
|
+
super(convert_key(key))
|
85
|
+
end
|
86
|
+
alias_method :has_key?, :key?
|
87
|
+
alias_method :include?, :key?
|
88
|
+
alias_method :member?, :key?
|
89
|
+
|
90
|
+
# Performs a deep_update on a duplicate of the
|
91
|
+
# current mash.
|
92
|
+
def deep_merge(other_hash, &blk)
|
93
|
+
dup.deep_update(other_hash, &blk)
|
94
|
+
end
|
95
|
+
alias_method :merge, :deep_merge
|
96
|
+
|
97
|
+
# Recursively merges this mash with the passed
|
98
|
+
# in hash, merging each hash in the hierarchy.
|
99
|
+
def deep_update(other_hash, &blk)
|
100
|
+
other_hash.each_pair do |k,v|
|
101
|
+
key = convert_key(k)
|
102
|
+
if regular_reader(key).is_a?(Mash) and v.is_a?(::Hash)
|
103
|
+
custom_reader(key).deep_update(v, &blk)
|
104
|
+
else
|
105
|
+
value = convert_value(v, true)
|
106
|
+
value = blk.call(key, self[k], value) if blk
|
107
|
+
custom_writer(key, value)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
self
|
111
|
+
end
|
112
|
+
alias_method :deep_merge!, :deep_update
|
113
|
+
alias_method :update, :deep_update
|
114
|
+
alias_method :merge!, :update
|
115
|
+
|
116
|
+
# Performs a shallow_update on a duplicate of the current mash
|
117
|
+
def shallow_merge(other_hash)
|
118
|
+
dup.shallow_update(other_hash)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Merges (non-recursively) the hash from the argument,
|
122
|
+
# changing the receiving hash
|
123
|
+
def shallow_update(other_hash)
|
124
|
+
other_hash.each_pair do |k,v|
|
125
|
+
regular_writer(convert_key(k), convert_value(v, true))
|
126
|
+
end
|
127
|
+
self
|
128
|
+
end
|
129
|
+
|
130
|
+
def replace(other_hash)
|
131
|
+
(keys - other_hash.keys).each { |key| delete(key) }
|
132
|
+
other_hash.each { |key, value| self[key] = value }
|
133
|
+
self
|
134
|
+
end
|
135
|
+
|
136
|
+
# Will return true if the Mash has had a key
|
137
|
+
# set in addition to normal respond_to? functionality.
|
138
|
+
def respond_to?(method_name, include_private=false)
|
139
|
+
return true if key?(method_name) || method_name.to_s.slice(/[=?!_]\Z/)
|
140
|
+
super
|
141
|
+
end
|
142
|
+
|
143
|
+
def method_missing(method_name, *args, &blk)
|
144
|
+
return self.[](method_name, &blk) if key?(method_name)
|
145
|
+
match = method_name.to_s.match(/(.*?)([?=!_]?)$/)
|
146
|
+
case match[2]
|
147
|
+
when "="
|
148
|
+
self[match[1]] = args.first
|
149
|
+
when "?"
|
150
|
+
!!self[match[1]]
|
151
|
+
when "!"
|
152
|
+
initializing_reader(match[1])
|
153
|
+
when "_"
|
154
|
+
underbang_reader(match[1])
|
155
|
+
else
|
156
|
+
default(method_name, *args, &blk)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
protected
|
161
|
+
|
162
|
+
def convert_key(key) #:nodoc:
|
163
|
+
key.to_s
|
164
|
+
end
|
165
|
+
|
166
|
+
def convert_value(val, duping=false) #:nodoc:
|
167
|
+
case val
|
168
|
+
when self.class
|
169
|
+
val.dup
|
170
|
+
when ::Hash
|
171
|
+
val = val.dup if duping
|
172
|
+
Mash.new(val)
|
173
|
+
when ::Array
|
174
|
+
val.map {|e| convert_value(e) }
|
175
|
+
else
|
176
|
+
val
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/lib/apihub/person.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module APIHub
|
2
2
|
class Person < Base
|
3
|
-
endpoint 'https://person.apihub.co'
|
3
|
+
endpoint 'https://person-stream.apihub.co'
|
4
4
|
path '/v1/people'
|
5
5
|
|
6
6
|
def self.find(values, options = {})
|
@@ -27,11 +27,7 @@ module APIHub
|
|
27
27
|
raise ArgumentError, 'Invalid values'
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
self.new(pending: true)
|
32
|
-
else
|
33
|
-
self.new(response)
|
34
|
-
end
|
30
|
+
self.new(response)
|
35
31
|
|
36
32
|
rescue Nestful::ResourceNotFound
|
37
33
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module APIHub
|
2
|
+
class Resource < Mash
|
3
|
+
def self.endpoint(value = nil)
|
4
|
+
@endpoint = value if value
|
5
|
+
return @endpoint if @endpoint
|
6
|
+
superclass.respond_to?(:endpoint) ? superclass.endpoint : nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.path(value = nil)
|
10
|
+
@path = value if value
|
11
|
+
return @path if @path
|
12
|
+
superclass.respond_to?(:path) ? superclass.path : nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.options(value = nil)
|
16
|
+
@options = value if value
|
17
|
+
return @options if @options
|
18
|
+
superclass.respond_to?(:options) ? superclass.options : {}
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
alias_method :endpoint=, :endpoint
|
23
|
+
alias_method :path=, :path
|
24
|
+
alias_method :options=, :options
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.url
|
28
|
+
URI.join(endpoint.to_s, path.to_s).to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.uri(*parts)
|
32
|
+
# If an absolute URI already
|
33
|
+
if (uri = parts.first) && uri.is_a?(URI)
|
34
|
+
return uri if uri.host
|
35
|
+
end
|
36
|
+
|
37
|
+
URI.parse(Nestful::Helpers.to_path(url, *parts))
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.get(action = '', params = {}, options = {})
|
41
|
+
request(uri(action), options.merge(method: :get, params: params))
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.put(action = '', params = {}, options = {})
|
45
|
+
request(uri(action), options.merge(method: :put, params: params))
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.post(action = '', params = {}, options = {})
|
49
|
+
request(uri(action), options.merge(method: :post, params: params))
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.delete(action = '', params = {}, options = {})
|
53
|
+
request(uri(action), options.merge(method: :delete, params: params))
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.request(url, options = {})
|
57
|
+
options = Nestful::Helpers.deep_merge(self.options, options)
|
58
|
+
|
59
|
+
self.new Nestful::Request.new(
|
60
|
+
url, options
|
61
|
+
).execute
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/apihub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apihub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex MacCaw
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,8 +69,11 @@ files:
|
|
69
69
|
- bin/apihub
|
70
70
|
- examples/email.rb
|
71
71
|
- lib/apihub.rb
|
72
|
+
- lib/apihub/base.rb
|
72
73
|
- lib/apihub/company.rb
|
74
|
+
- lib/apihub/mash.rb
|
73
75
|
- lib/apihub/person.rb
|
76
|
+
- lib/apihub/resource.rb
|
74
77
|
- lib/apihub/version.rb
|
75
78
|
homepage: https://github.com/maccman/apihub-ruby
|
76
79
|
licenses:
|