grifter 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,33 +1,65 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ addressable (2.3.5)
4
5
  awesome_print (1.1.0)
6
+ builder (3.2.2)
5
7
  coderay (1.0.9)
6
8
  diff-lcs (1.2.4)
9
+ faraday (0.8.8)
10
+ multipart-post (~> 1.2.0)
7
11
  git (1.2.5)
8
- jeweler (1.8.4)
12
+ github_api (0.10.1)
13
+ addressable
14
+ faraday (~> 0.8.1)
15
+ hashie (>= 1.2)
16
+ multi_json (~> 1.4)
17
+ nokogiri (~> 1.5.2)
18
+ oauth2
19
+ hashie (2.0.5)
20
+ highline (1.6.19)
21
+ httpauth (0.2.0)
22
+ jeweler (1.8.6)
23
+ builder
9
24
  bundler (~> 1.0)
10
25
  git (>= 1.2.5)
26
+ github_api (= 0.10.1)
27
+ highline (>= 1.6.15)
28
+ nokogiri (= 1.5.10)
11
29
  rake
12
30
  rdoc
13
- json (1.7.7)
14
- method_source (0.8.1)
15
- pry (0.9.12.1)
31
+ json (1.8.0)
32
+ jwt (0.1.8)
33
+ multi_json (>= 1.5)
34
+ method_source (0.8.2)
35
+ multi_json (1.7.8)
36
+ multi_xml (0.5.4)
37
+ multipart-post (1.2.0)
38
+ nokogiri (1.5.10)
39
+ oauth2 (0.9.2)
40
+ faraday (~> 0.8)
41
+ httpauth (~> 0.2)
42
+ jwt (~> 0.1.4)
43
+ multi_json (~> 1.0)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ pry (0.9.12.2)
16
47
  coderay (~> 1.0.5)
17
48
  method_source (~> 0.8)
18
49
  slop (~> 3.4)
19
- rake (10.0.4)
50
+ rack (1.5.2)
51
+ rake (10.1.0)
20
52
  rdoc (4.0.1)
21
53
  json (~> 1.4)
22
- rspec (2.13.0)
23
- rspec-core (~> 2.13.0)
24
- rspec-expectations (~> 2.13.0)
25
- rspec-mocks (~> 2.13.0)
26
- rspec-core (2.13.1)
27
- rspec-expectations (2.13.0)
54
+ rspec (2.14.1)
55
+ rspec-core (~> 2.14.0)
56
+ rspec-expectations (~> 2.14.0)
57
+ rspec-mocks (~> 2.14.0)
58
+ rspec-core (2.14.4)
59
+ rspec-expectations (2.14.0)
28
60
  diff-lcs (>= 1.1.3, < 2.0)
29
- rspec-mocks (2.13.1)
30
- slop (3.4.4)
61
+ rspec-mocks (2.14.2)
62
+ slop (3.4.6)
31
63
 
32
64
  PLATFORMS
33
65
  ruby
data/grifter.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "grifter"
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert Schultheis"]
12
- s.date = "2013-07-09"
12
+ s.date = "2013-08-05"
13
13
  s.description = "convention based approach to interfacing with an HTTP JSON API."
14
14
  s.email = "rob@knewton.com"
15
15
  s.executables = ["grift"]
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.homepage = "http://github.com/knewton/grifter"
35
35
  s.licenses = ["MIT"]
36
36
  s.require_paths = ["lib"]
37
- s.rubygems_version = "1.8.24"
37
+ s.rubygems_version = "1.8.23"
38
38
  s.summary = "Make calls to HTTP JSON APIs with ease and confidence"
39
39
 
40
40
  if s.respond_to? :specification_version then
@@ -19,6 +19,8 @@ class Grifter
19
19
  @http = Net::HTTP.new(@config[:hostname], @config[:port])
20
20
  @http.use_ssl = @config[:ssl]
21
21
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @config[:ignore_ssl_cert]
22
+ @http.read_timeout = @config[:timeout] if @config[:timeout]
23
+ p @config
22
24
 
23
25
  @headers = {
24
26
  'accept' => 'application/json',
@@ -42,12 +44,29 @@ class Grifter
42
44
  attr_reader :last_request, :last_response
43
45
 
44
46
  RequestLogSeperator = '-'*40
45
- def do_request req
47
+
48
+ # do_request performs the actual request, and does associated logging
49
+ # options can include:
50
+ # - :timeout, which specifies num secs the request should timeout in
51
+ # (this turns out to be kind of annoying to implement)
52
+ def do_request req, options={}
46
53
  Log.debug RequestLogSeperator
47
54
  Log.debug "#{req.class} #{req.path}"
48
55
  Log.debug "HEADERS: #{req.to_hash}"
49
56
  Log.debug "BODY:\n#{req.body}" if req.request_body_permitted?
57
+
58
+ if options.has_key? :timeout
59
+ cur_timeout = @http.read_timeout
60
+ Log.debug "Overriding timeout to: #{options[:timeout]}"
61
+ @http.read_timeout = options[:timeout]
62
+ end
63
+
50
64
  response = @http.request(req)
65
+
66
+ if cur_timeout
67
+ @http.read_timeout = cur_timeout
68
+ end
69
+
51
70
  Log.debug "RESPONSE CODE: #{response.code}"
52
71
  Log.debug "RESPONSE HEADERS: #{response.to_hash}"
53
72
  Log.debug "RESPONSE BODY:\n#{jsonify response.body}\n"
@@ -86,46 +105,46 @@ class Grifter
86
105
 
87
106
  def get path, options={}
88
107
  req = Net::HTTP::Get.new(*req_args(path, options))
89
- do_request req
108
+ do_request req, options
90
109
  end
91
110
 
92
111
  def head path, options={}
93
112
  req = Net::HTTP::Head.new(*req_args(path, options))
94
- do_request req
113
+ do_request req, options
95
114
  end
96
115
 
97
116
  def options path, options={}
98
117
  req = Net::HTTP::Options.new(*req_args(path, options))
99
- do_request req
118
+ do_request req, options
100
119
  end
101
120
 
102
121
  def delete path, options={}
103
122
  req = Net::HTTP::Delete.new(*req_args(path, options))
104
- do_request req
123
+ do_request req, options
105
124
  end
106
125
 
107
126
  def post path, obj, options={}
108
127
  req = Net::HTTP::Post.new(*req_args(path, options))
109
128
  req.body = jsonify(obj)
110
- do_request req
129
+ do_request req, options
111
130
  end
112
131
 
113
132
  def put path, obj, options={}
114
133
  req = Net::HTTP::Put.new(*req_args(path, options))
115
134
  req.body = jsonify(obj)
116
- do_request req
135
+ do_request req, options
117
136
  end
118
137
 
119
138
  def patch path, obj, options={}
120
139
  req = Net::HTTP::Patch.new(*req_args(path, options))
121
140
  req.body = jsonify(obj)
122
- do_request req
141
+ do_request req, options
123
142
  end
124
143
 
125
144
  def post_form path, params, options={}
126
145
  request_obj = Net::HTTP::Post.new(*req_args(path, options))
127
146
  request_obj.set_form_data params
128
- do_request request_obj
147
+ do_request request_obj, options
129
148
  end
130
149
  end
131
150
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grifter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-09 00:00:00.000000000 Z
12
+ date: 2013-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: 1820127751693407514
130
+ hash: 664082340422287715
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements:
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 1.8.24
139
+ rubygems_version: 1.8.23
140
140
  signing_key:
141
141
  specification_version: 3
142
142
  summary: Make calls to HTTP JSON APIs with ease and confidence