rainmaker 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/README.md +14 -8
- data/lib/faraday/response/rainmaker_errors.rb +14 -14
- data/lib/faraday/response/raise_http_4xx.rb +3 -3
- data/lib/rainmaker/client/person.rb +3 -3
- data/lib/rainmaker/configuration.rb +14 -4
- data/lib/rainmaker/request.rb +22 -17
- data/lib/rainmaker/version.rb +1 -1
- data/spec/faraday/response_spec.rb +5 -5
- data/spec/rainmaker_spec.rb +59 -26
- data/spec/ruby_rainmaker/api_spec.rb +3 -1
- metadata +28 -28
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -15,17 +15,23 @@ Usage Examples
|
|
15
15
|
require "rubygems"
|
16
16
|
require "rainmaker"
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
# This could go in an initializer
|
19
|
+
Rainmaker.configure do |config|
|
20
|
+
config.api_key = "rainmaker_api_key_goes_here"
|
21
|
+
config.timeout_seconds = "30" # value will be used for all requests unless overridden
|
22
|
+
config.twitter_token = "twitter_token_goes_here" # contact support@rainmaker.cc for details
|
23
|
+
config.linkedin_token = "linked_in_token_goes_here" # contact support@rainmaker.cc for details
|
24
|
+
end
|
25
|
+
|
23
26
|
# Get information about an email address
|
24
27
|
person = Rainmaker.person("brawest@gmail.com")
|
28
|
+
|
29
|
+
# Get person's family_name
|
30
|
+
puts person.contact_info.family_name
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
# Override timeout_seconds for single call
|
33
|
+
person = Rainmaker.person("brawest@gmail.com", { :timeout_seconds => "0" })
|
34
|
+
|
29
35
|
Copyright
|
30
36
|
---------
|
31
37
|
Copyright (c) 2011 Brandon West
|
@@ -1,27 +1,27 @@
|
|
1
1
|
module Faraday
|
2
2
|
class Response::RainmakerErrors < Response::Middleware
|
3
3
|
def on_complete(env)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
case env[:status]
|
5
|
+
when 400
|
6
|
+
raise Rainmaker::BadRequest.new(error_message(env), env[:response_headers])
|
7
|
+
when 401
|
8
|
+
raise Rainmaker::Unauthorized.new(error_message(env), env[:response_headers])
|
9
|
+
when 403
|
10
|
+
raise Rainmaker::Forbidden.new(error_message(env), env[:response_headers])
|
11
|
+
when 404
|
12
|
+
raise Rainmaker::NotFound.new(error_message(env), env[:response_headers])
|
13
|
+
when 422
|
14
|
+
raise Rainmaker::Invalid.new(error_message(env), env[:response_headers])
|
15
|
+
when 500
|
16
16
|
raise Rainmaker::InternalServerError.new(error_message(env), env[:response_headers])
|
17
17
|
when 502
|
18
18
|
raise Rainmaker::BadGateway.new(error_message(env), env[:response_headers])
|
19
19
|
when 503
|
20
20
|
raise Rainmaker::ServiceUnavailable.new(error_message(env), env[:response_headers])
|
21
21
|
end
|
22
|
-
|
22
|
+
end
|
23
23
|
|
24
|
-
|
24
|
+
def error_message(env)
|
25
25
|
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}"
|
26
26
|
end
|
27
27
|
|
@@ -4,10 +4,10 @@ module Rainmaker
|
|
4
4
|
# Returns extended information for a given email
|
5
5
|
#
|
6
6
|
def person(email, options = {})
|
7
|
-
|
7
|
+
options[:email] = email
|
8
8
|
response = get('person', options)
|
9
9
|
format.to_s.downcase == 'xml' ? response['person'] : response
|
10
|
-
|
11
|
-
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
13
13
|
end
|
@@ -7,11 +7,13 @@ module Rainmaker
|
|
7
7
|
VALID_OPTIONS_KEYS = [
|
8
8
|
:adapter,
|
9
9
|
:api_key,
|
10
|
-
|
10
|
+
:timeout_seconds,
|
11
11
|
:endpoint,
|
12
12
|
:format,
|
13
13
|
:gateway,
|
14
14
|
:proxy,
|
15
|
+
:linkedin_token,
|
16
|
+
:twitter_token,
|
15
17
|
:user_agent].freeze
|
16
18
|
|
17
19
|
# An array of valid request/response formats
|
@@ -27,7 +29,7 @@ module Rainmaker
|
|
27
29
|
# By default, don't set an application key
|
28
30
|
DEFAULT_API_KEY = nil
|
29
31
|
|
30
|
-
|
32
|
+
# By default, don't set a timeout
|
31
33
|
DEFAULT_TIMEOUT_SECONDS = nil
|
32
34
|
|
33
35
|
# The endpoint that will be used to connect if none is set
|
@@ -41,6 +43,12 @@ module Rainmaker
|
|
41
43
|
|
42
44
|
# By default, don't use a proxy server
|
43
45
|
DEFAULT_PROXY = nil
|
46
|
+
|
47
|
+
# By default, no linkedin token
|
48
|
+
DEFAULT_LINKEDIN_TOKEN = nil
|
49
|
+
|
50
|
+
# By default, no twitter token
|
51
|
+
DEFAULT_TWITTER_TOKEN = nil
|
44
52
|
|
45
53
|
# The user agent that will be sent to the API endpoint if none is set
|
46
54
|
DEFAULT_USER_AGENT = "Rainmaker Ruby Gem".freeze
|
@@ -70,13 +78,15 @@ module Rainmaker
|
|
70
78
|
# Reset all configuration options to defaults
|
71
79
|
def reset
|
72
80
|
self.adapter = DEFAULT_ADAPTER
|
73
|
-
self.api_key
|
81
|
+
self.api_key = DEFAULT_API_KEY
|
74
82
|
self.endpoint = DEFAULT_ENDPOINT
|
75
83
|
self.format = DEFAULT_FORMAT
|
76
84
|
self.proxy = DEFAULT_PROXY
|
77
85
|
self.user_agent = DEFAULT_USER_AGENT
|
78
86
|
self.gateway = DEFAULT_GATEWAY
|
79
|
-
|
87
|
+
self.timeout_seconds = DEFAULT_TIMEOUT_SECONDS
|
88
|
+
self.twitter_token = DEFAULT_TWITTER_TOKEN
|
89
|
+
self.linkedin_token = DEFAULT_LINKEDIN_TOKEN
|
80
90
|
self
|
81
91
|
end
|
82
92
|
end
|
data/lib/rainmaker/request.rb
CHANGED
@@ -12,32 +12,37 @@ module Rainmaker
|
|
12
12
|
|
13
13
|
# Perform an HTTP request
|
14
14
|
def request(method, path, options, raw=false)
|
15
|
-
|
16
|
-
|
15
|
+
#check to see if apiKey and timeoutSeconds options were passed in
|
16
|
+
#set them from Rainmaker.options if not
|
17
17
|
|
18
|
-
|
18
|
+
options[:api_key] = Rainmaker.options[:api_key] if options[:api_key].nil?
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
if options[:timeout_seconds].nil?
|
21
|
+
options[:timeout_seconds] = Rainmaker.options[:timeout_seconds] unless Rainmaker.options[:timeout_seconds].nil?
|
22
|
+
end
|
23
23
|
|
24
|
-
|
24
|
+
options[:linkedin_token] = Rainmaker.options[:linkedin_token] unless Rainmaker.options[:linkedin_token].nil?
|
25
|
+
options[:twitter_token] = Rainmaker.options[:twitter_token] unless Rainmaker.options[:twitter_token].nil?
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
query_params = QueryParams.new(options)
|
28
|
+
|
29
|
+
response = connection(raw).send(method) do |request|
|
30
|
+
request.url(formatted_path(path), query_params)
|
31
|
+
end
|
29
32
|
|
30
|
-
|
33
|
+
raw ? response : response.body
|
31
34
|
end
|
32
35
|
|
33
36
|
def formatted_path(path)
|
34
37
|
[path, format].compact.join('.')
|
35
|
-
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
class QueryParams < Hashie::Trash
|
41
|
+
property :apiKey, :from => :api_key
|
42
|
+
property :timeoutSeconds, :from => :timeout_seconds
|
43
|
+
property :lt, :from => :linkedin_token
|
44
|
+
property :tt, :from => :twitter_token
|
45
|
+
property :email
|
46
|
+
end
|
42
47
|
end
|
43
48
|
end
|
data/lib/rainmaker/version.rb
CHANGED
@@ -4,9 +4,9 @@ require 'rainmaker'
|
|
4
4
|
|
5
5
|
describe Faraday::Response do
|
6
6
|
before do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
Rainmaker.configure do |config|
|
8
|
+
config.api_key = "api_key"
|
9
|
+
end
|
10
10
|
@client = Rainmaker::Client.new
|
11
11
|
end
|
12
12
|
|
@@ -39,8 +39,8 @@ describe Faraday::Response do
|
|
39
39
|
context "when HTTP status is #{status} and body is #{body||='nil'}" do
|
40
40
|
before do
|
41
41
|
body_message = '{"'+body+'":"test"}' unless body.nil?
|
42
|
-
|
43
|
-
|
42
|
+
stub_get('person.json').
|
43
|
+
with(:query => {:apiKey => "api_key", :email => 'brawest@gmail.com'}).
|
44
44
|
to_return(:status => status, :body => body_message)
|
45
45
|
end
|
46
46
|
|
data/spec/rainmaker_spec.rb
CHANGED
@@ -8,48 +8,81 @@ describe Rainmaker do
|
|
8
8
|
context "when delegating to a client" do
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
Rainmaker.configure do |config|
|
12
|
+
config.api_key = "api_key"
|
13
|
+
end
|
14
|
+
|
15
|
+
stub_get("person.json").
|
16
|
+
with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}).
|
17
|
+
to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
18
|
+
|
19
|
+
stub_get("person.json").
|
20
|
+
with(:query => {:apiKey => "passed_api_key", :email => "brawest@gmail.com", :timeoutSeconds => "passed_timeout"}).
|
21
|
+
to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
22
|
+
|
23
|
+
stub_get("person.json").
|
24
|
+
with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :timeoutSeconds => "from_config"}).
|
25
|
+
to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
|
27
|
+
stub_get("person.json").
|
28
|
+
with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :lt => "from_config"}).
|
29
|
+
to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
18
30
|
|
19
|
-
|
20
|
-
|
21
|
-
|
31
|
+
stub_get("person.json").
|
32
|
+
with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :tt => "from_config"}).
|
33
|
+
to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
22
34
|
|
23
|
-
|
24
|
-
|
25
|
-
|
35
|
+
stub_get("person.json").
|
36
|
+
with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :timeoutSeconds => "0"}).
|
37
|
+
to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
26
38
|
end
|
27
39
|
|
28
40
|
it "should get the correct resource" do
|
29
41
|
Rainmaker.person("brawest@gmail.com")
|
30
42
|
a_get("person.json")
|
31
|
-
|
32
|
-
|
43
|
+
.with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"})
|
44
|
+
.should have_been_made
|
33
45
|
end
|
34
46
|
|
35
|
-
|
47
|
+
it "should get person with provided api_key and timeout_seconds" do
|
36
48
|
Rainmaker.person("brawest@gmail.com", {:api_key => "passed_api_key", :timeout_seconds => "passed_timeout"})
|
37
49
|
a_get("person.json")
|
38
|
-
|
39
|
-
|
50
|
+
.with(:query => {:apiKey => "passed_api_key", :email => "brawest@gmail.com", :timeoutSeconds => "passed_timeout"})
|
51
|
+
.should have_been_made
|
40
52
|
end
|
41
53
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
54
|
+
it "should use timeout_seconds from config if not passed in" do
|
55
|
+
Rainmaker.configure do |config|
|
56
|
+
config.timeout_seconds = "from_config"
|
57
|
+
end
|
46
58
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
59
|
+
Rainmaker.person("brawest@gmail.com")
|
60
|
+
a_get("person.json")
|
61
|
+
.with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :timeoutSeconds => "from_config"})
|
62
|
+
.should have_been_made
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should use linkedin_token from config if existing" do
|
66
|
+
Rainmaker.configure do |config|
|
67
|
+
config.linkedin_token = "from_config"
|
68
|
+
end
|
69
|
+
|
70
|
+
Rainmaker.person("brawest@gmail.com")
|
71
|
+
a_get("person.json")
|
72
|
+
.with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :lt => "from_config"})
|
73
|
+
.should have_been_made
|
74
|
+
end
|
51
75
|
|
52
|
-
|
76
|
+
it "should use twitter_token from config if existing" do
|
77
|
+
Rainmaker.configure do |config|
|
78
|
+
config.twitter_token = "from_config"
|
79
|
+
end
|
80
|
+
|
81
|
+
Rainmaker.person("brawest@gmail.com")
|
82
|
+
a_get("person.json")
|
83
|
+
.with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :tt => "from_config"})
|
84
|
+
.should have_been_made
|
85
|
+
end
|
53
86
|
|
54
87
|
it "should return the same results as a client" do
|
55
88
|
Rainmaker.person("brawest@gmail.com").should == Rainmaker::Client.new.person("brawest@gmail.com")
|
@@ -36,7 +36,9 @@ describe Rainmaker::API do
|
|
36
36
|
:format => :xml,
|
37
37
|
:proxy => 'http://erik:sekret@proxy.example.com:8080',
|
38
38
|
:user_agent => 'Custom User Agent',
|
39
|
-
|
39
|
+
:timeout_seconds => "Timeout Seconds",
|
40
|
+
:linkedin_token => "LinkedIn Token",
|
41
|
+
:twitter_token => "Twitter Token"
|
40
42
|
}
|
41
43
|
end
|
42
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rainmaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: maruku
|
16
|
-
requirement: &
|
16
|
+
requirement: &11102280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11102280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &11101980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.4'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11101980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &11101704 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.9'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *11101704
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &11101428 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '2.6'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *11101428
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &11101152 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0.4'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *11101152
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
|
-
requirement: &
|
71
|
+
requirement: &11100876 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '1.6'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *11100876
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: yard
|
82
|
-
requirement: &
|
82
|
+
requirement: &11100600 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0.7'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *11100600
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: hashie
|
93
|
-
requirement: &
|
93
|
+
requirement: &11100324 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 1.0.0
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *11100324
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: faraday
|
104
|
-
requirement: &
|
104
|
+
requirement: &11118468 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 0.6.1
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *11118468
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: faraday_middleware
|
115
|
-
requirement: &
|
115
|
+
requirement: &11118192 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ~>
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 0.6.3
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *11118192
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: multi_json
|
126
|
-
requirement: &
|
126
|
+
requirement: &11117916 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ~>
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: 1.0.0
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *11117916
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: multi_xml
|
137
|
-
requirement: &
|
137
|
+
requirement: &11117640 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ~>
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: 0.2.0
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *11117640
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: rash
|
148
|
-
requirement: &
|
148
|
+
requirement: &11117364 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ~>
|
@@ -153,7 +153,7 @@ dependencies:
|
|
153
153
|
version: 0.3.0
|
154
154
|
type: :runtime
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *11117364
|
157
157
|
description: A Ruby wrapper for the Rainmaker API
|
158
158
|
email:
|
159
159
|
- brawest@gmail.com
|