apihub 0.0.4 → 0.0.5

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: d231af661f63c2dc86ddfe2da989e9712799c342
4
- data.tar.gz: a0a51be9f1547752c47489bd6cbfa2c636453e34
3
+ metadata.gz: 968c7728de504c70dd18e6e8a07ede0c86208eea
4
+ data.tar.gz: ebf452723ba3193ef318d7173c5489f4f2ee385d
5
5
  SHA512:
6
- metadata.gz: e0b8a236f1b7959d2d8878144bb0fd4cede913f15181f662347087a469042dc4d98cf122d0d0420193ed32e5c593d328e89b08a4bcc72ad5c1a60c277cd3395b
7
- data.tar.gz: a4972990d7942613761a32f30260e0b0982c6069d02600b934bf6796a260c63afbc09cff82a5dd6eab0e0e4e00c10f07ff08cef8bbe917853b0b13feb737ac89
6
+ metadata.gz: 4f439d4701289989682fc21f06f4b3b9312709d744d213d0a7babfbf2294877c28cda23101faa53b40085d26235548e56623700788f4afdcff965349cc1f2115
7
+ data.tar.gz: 23c14c0544c262886bb8c32774b0557cff0a4404dc880d56c07c35e6cf01a2200e92df6d56e56e655308d0ca61df73cc184c87fb828cfc070f50124bfc805286
data/README.md CHANGED
@@ -40,6 +40,21 @@ If the company can't be found, then `nil` will be returned.
40
40
 
41
41
  See the [documentation](https://apihub.co/docs/company) for more information.
42
42
 
43
+ ## Streaming requests
44
+
45
+ Often you'll want people or company lookups to block, rather than return blank `202` requests if we need to look up data. You can do this using APIHub's streaming API.
46
+
47
+ For example, to look up a company by domain using our streaming API use the `APIHub::Streaming::Company` class:
48
+
49
+ company = APIHub::Streaming::Company[domain: 'uber.com']
50
+
51
+ If we need to lookup the company, we'll block the network request for 10-20 seconds before responding. This is ideal for scenarios where long network requests don't really matter, such as job queues. Often the streaming API will be easier to implement than webhooks.
52
+
53
+ You can similarity look up people using the `APIHub::Streaming::Person` class.
54
+
55
+ person = APIHub::Streaming::Person[email: 'info@eribium.org']
56
+
57
+
43
58
  ## CLI
44
59
 
45
60
  The gem also includes a `apihub` executable, which you can use like this:
data/bin/apihub CHANGED
@@ -18,14 +18,6 @@ values = {}
18
18
  parser = OptionParser.new do |opts|
19
19
  opts.banner = "Usage: apihub [person|company] [options]"
20
20
 
21
- opts.on("--twitter HANDLE", String, "Twitter handle") do |v|
22
- values[:twitter] = v
23
- end
24
-
25
- opts.on("--github HANDLE", String, "GitHub handle") do |v|
26
- values[:github] = v
27
- end
28
-
29
21
  opts.on("--email EMAIL", String, "Email") do |v|
30
22
  values[:email] = v
31
23
  end
@@ -43,9 +35,9 @@ parser.parse!
43
35
 
44
36
  case ARGV[0]
45
37
  when 'person'
46
- entity = APIHub::Person
38
+ entity = APIHub::Streaming::Person
47
39
  when 'company'
48
- entity = APIHub::Company
40
+ entity = APIHub::Streaming::Company
49
41
  else
50
42
  puts parser
51
43
  exit
@@ -60,11 +52,17 @@ if key = ENV['APIHUB_KEY']
60
52
  options[:api_key] ||= key
61
53
  end
62
54
 
55
+ if key = options.delete(:api_key)
56
+ APIHub.api_key = key
57
+ else
58
+ puts 'API Key required'
59
+ puts parser
60
+ exit
61
+ end
62
+
63
63
  object = entity.find(values, options)
64
64
 
65
- if object && object.pending?
66
- puts 'Lookup queued'
67
- elsif object
65
+ if object
68
66
  ap object.to_hash
69
67
  else
70
68
  puts 'Not found'
@@ -18,4 +18,5 @@ module APIHub
18
18
  autoload :Mash, 'apihub/mash'
19
19
  autoload :Person, 'apihub/person'
20
20
  autoload :Resource, 'apihub/resource'
21
+ autoload :Streaming, 'apihub/streaming'
21
22
  end
@@ -1,6 +1,6 @@
1
1
  module APIHub
2
2
  class Company < Base
3
- endpoint 'https://company-stream.apihub.co'
3
+ endpoint 'https://company.apihub.co'
4
4
  path '/v1/companies'
5
5
 
6
6
  def self.find(values, options = {})
@@ -21,7 +21,11 @@ module APIHub
21
21
  raise ArgumentError, 'Invalid values'
22
22
  end
23
23
 
24
- self.new(response)
24
+ if response.status == 202
25
+ self.new(pending: true)
26
+ else
27
+ self.new(response)
28
+ end
25
29
 
26
30
  rescue Nestful::ResourceNotFound
27
31
  end
@@ -1,6 +1,6 @@
1
1
  module APIHub
2
2
  class Person < Base
3
- endpoint 'https://person-stream.apihub.co'
3
+ endpoint 'https://person.apihub.co'
4
4
  path '/v1/people'
5
5
 
6
6
  def self.find(values, options = {})
@@ -27,7 +27,11 @@ module APIHub
27
27
  raise ArgumentError, 'Invalid values'
28
28
  end
29
29
 
30
- self.new(response)
30
+ if response.status == 202
31
+ self.new(pending: true)
32
+ else
33
+ self.new(response)
34
+ end
31
35
 
32
36
  rescue Nestful::ResourceNotFound
33
37
  end
@@ -0,0 +1,6 @@
1
+ module APIHub
2
+ module Streaming
3
+ autoload :Company, 'apihub/streaming/company'
4
+ autoload :Person, 'apihub/streaming/person'
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module APIHub
2
+ module Streaming
3
+ class Company < APIHub::Company
4
+ endpoint 'https://company-stream.apihub.co'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module APIHub
2
+ module Streaming
3
+ class Person < APIHub::Person
4
+ endpoint 'https://person-stream.apihub.co'
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module APIHub
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apihub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw
@@ -74,6 +74,9 @@ files:
74
74
  - lib/apihub/mash.rb
75
75
  - lib/apihub/person.rb
76
76
  - lib/apihub/resource.rb
77
+ - lib/apihub/streaming.rb
78
+ - lib/apihub/streaming/company.rb
79
+ - lib/apihub/streaming/person.rb
77
80
  - lib/apihub/version.rb
78
81
  homepage: https://github.com/maccman/apihub-ruby
79
82
  licenses: