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 CHANGED
@@ -27,7 +27,7 @@ pkg
27
27
  #
28
28
  # For MacOS:
29
29
  #
30
- #.DS_Store
30
+ .DS_Store
31
31
 
32
32
  # For TextMate
33
33
  #*.tmproj
data/README.md CHANGED
@@ -15,17 +15,23 @@ Usage Examples
15
15
  require "rubygems"
16
16
  require "rainmaker"
17
17
 
18
- # This could go in an initializer
19
- Rainmaker.configure do |config|
20
- config.api_key = "rainmaker_api_key_goes_here"
21
- end
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
- # Get person's family_name
27
- puts person.contact_info.family_name
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
- 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
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
- end
22
+ end
23
23
 
24
- def error_message(env)
24
+ def error_message(env)
25
25
  "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}"
26
26
  end
27
27
 
@@ -19,11 +19,11 @@ module Faraday
19
19
  end
20
20
 
21
21
 
22
- end
22
+ end
23
23
 
24
- private
24
+ private
25
25
 
26
- def error_message(env)
26
+ def error_message(env)
27
27
  "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
28
28
  end
29
29
 
@@ -4,10 +4,10 @@ module Rainmaker
4
4
  # Returns extended information for a given email
5
5
  #
6
6
  def person(email, options = {})
7
- options[:email] = email
7
+ options[:email] = email
8
8
  response = get('person', options)
9
9
  format.to_s.downcase == 'xml' ? response['person'] : response
10
- end
11
- end
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
- :timeout_seconds,
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
- # By default, don't set a timeout
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 = DEFAULT_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
- self.timeout_seconds = DEFAULT_TIMEOUT_SECONDS
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
@@ -12,32 +12,37 @@ module Rainmaker
12
12
 
13
13
  # Perform an HTTP request
14
14
  def request(method, path, options, raw=false)
15
- #check to see if apiKey and timeoutSeconds options were passed in
16
- #set them from Rainmaker.options if not
15
+ #check to see if apiKey and timeoutSeconds options were passed in
16
+ #set them from Rainmaker.options if not
17
17
 
18
- options[:api_key] = Rainmaker.options[:api_key] if options[:api_key].nil?
18
+ options[:api_key] = Rainmaker.options[:api_key] if options[:api_key].nil?
19
19
 
20
- if options[:timeout_seconds].nil?
21
- options[:timeout_seconds] = Rainmaker.options[:timeout_seconds] unless Rainmaker.options[:timeout_seconds].nil?
22
- end
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
- query_params = QueryParams.new(options)
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
- response = connection(raw).send(method) do |request|
27
- request.url(formatted_path(path), query_params)
28
- end
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
- raw ? response : response.body
33
+ raw ? response : response.body
31
34
  end
32
35
 
33
36
  def formatted_path(path)
34
37
  [path, format].compact.join('.')
35
- end
38
+ end
36
39
 
37
- class QueryParams < Hashie::Trash
38
- property :apiKey, :from => :api_key
39
- property :timeoutSeconds, :from => :timeout_seconds
40
- property :email
41
- end
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
@@ -1,3 +1,3 @@
1
1
  module Rainmaker
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -4,9 +4,9 @@ require 'rainmaker'
4
4
 
5
5
  describe Faraday::Response do
6
6
  before do
7
- Rainmaker.configure do |config|
8
- config.api_key = "api_key"
9
- end
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
- stub_get('person.json').
43
- with(:query => {:apiKey => "api_key", :email => 'brawest@gmail.com'}).
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
 
@@ -8,48 +8,81 @@ describe Rainmaker do
8
8
  context "when delegating to a client" do
9
9
 
10
10
  before do
11
- Rainmaker.configure do |config|
12
- config.api_key = "api_key"
13
- end
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
- 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"})
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
- 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"})
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
- 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"})
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
- .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"})
32
- .should have_been_made
43
+ .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"})
44
+ .should have_been_made
33
45
  end
34
46
 
35
- it "should get person with provided api_key and timeout_seconds" do
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
- .with(:query => {:apiKey => "passed_api_key", :email => "brawest@gmail.com", :timeoutSeconds => "passed_timeout"})
39
- .should have_been_made
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
- it "should us timeout_seconds from config if not passed in" do
43
- Rainmaker.configure do |config|
44
- config.timeout_seconds = "from_config"
45
- end
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
- Rainmaker.person("brawest@gmail.com")
48
- a_get("person.json")
49
- .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com", :timeoutSeconds => "from_config"})
50
- .should have_been_made
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
- end
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
- :timeout_seconds => "Timeout Seconds"
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
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-02 00:00:00.000000000Z
12
+ date: 2011-06-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: maruku
16
- requirement: &11032644 !ruby/object:Gem::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: *11032644
24
+ version_requirements: *11102280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &11032344 !ruby/object:Gem::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: *11032344
35
+ version_requirements: *11101980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &11032068 !ruby/object:Gem::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: *11032068
46
+ version_requirements: *11101704
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &11031792 !ruby/object:Gem::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: *11031792
57
+ version_requirements: *11101428
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &11031516 !ruby/object:Gem::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: *11031516
68
+ version_requirements: *11101152
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
- requirement: &11031240 !ruby/object:Gem::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: *11031240
79
+ version_requirements: *11100876
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &11030964 !ruby/object:Gem::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: *11030964
90
+ version_requirements: *11100600
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: hashie
93
- requirement: &11030688 !ruby/object:Gem::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: *11030688
101
+ version_requirements: *11100324
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: faraday
104
- requirement: &19150740 !ruby/object:Gem::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: *19150740
112
+ version_requirements: *11118468
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: faraday_middleware
115
- requirement: &19150464 !ruby/object:Gem::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: *19150464
123
+ version_requirements: *11118192
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: multi_json
126
- requirement: &19150188 !ruby/object:Gem::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: *19150188
134
+ version_requirements: *11117916
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: multi_xml
137
- requirement: &19149912 !ruby/object:Gem::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: *19149912
145
+ version_requirements: *11117640
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: rash
148
- requirement: &19149636 !ruby/object:Gem::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: *19149636
156
+ version_requirements: *11117364
157
157
  description: A Ruby wrapper for the Rainmaker API
158
158
  email:
159
159
  - brawest@gmail.com