twurl 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/twurl/cli.rb CHANGED
@@ -92,10 +92,12 @@ module Twurl
92
92
 
93
93
  def print(*args, &block)
94
94
  output.print(*args, &block)
95
+ output.flush if output.respond_to?(:flush)
95
96
  end
96
97
 
97
98
  def puts(*args, &block)
98
99
  output.puts(*args, &block)
100
+ output.flush if output.respond_to?(:flush)
99
101
  end
100
102
 
101
103
  def prompt_for(label)
@@ -62,21 +62,22 @@ module Twurl
62
62
  configure_http!
63
63
  end
64
64
 
65
- [:get, :post, :put, :delete, :options, :head, :copy].each do |request_method|
66
- class_eval(<<-EVAL, __FILE__, __LINE__)
67
- def #{request_method}(url, *options)
68
- # configure_http!
69
- access_token.#{request_method}(url, *options)
70
- end
71
- EVAL
72
- end
73
-
74
- def perform_request_from_options(options)
75
- if [:post, :put].include?(options.request_method.to_sym)
76
- send(options.request_method, options.path, options.data, options.headers)
77
- else
78
- send(options.request_method, options.path, options.headers)
79
- end
65
+ METHODS = {
66
+ :post => Net::HTTP::Post,
67
+ :get => Net::HTTP::Get,
68
+ :put => Net::HTTP::Put,
69
+ :delete => Net::HTTP::Delete,
70
+ :options => Net::HTTP::Options,
71
+ :head => Net::HTTP::Head,
72
+ :copy => Net::HTTP::Copy
73
+ }
74
+
75
+ def perform_request_from_options(options, &block)
76
+ request_class = METHODS.fetch(options.request_method.to_sym)
77
+ request = request_class.new(options.path, options.headers)
78
+ request.set_form_data(options.data) if options.data
79
+ request.oauth!(consumer.http, consumer, access_token)
80
+ consumer.http.request(request, &block)
80
81
  end
81
82
 
82
83
  def exchange_credentials_for_access_token
@@ -10,8 +10,9 @@ module Twurl
10
10
  end
11
11
 
12
12
  def perform_request
13
- response = client.perform_request_from_options(options)
14
- CLI.print response.body
13
+ client.perform_request_from_options(options) { |response|
14
+ response.read_body { |chunk| CLI.print chunk }
15
+ }
15
16
  rescue URI::InvalidURIError
16
17
  CLI.puts NO_URI_MESSAGE
17
18
  end
data/lib/twurl/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Twurl
2
2
  module VERSION
3
3
  MAJOR = '0' unless defined? MAJOR
4
- MINOR = '6' unless defined? MINOR
5
- PATCH = '7' unless defined? PATCH
4
+ MINOR = '7' unless defined? MINOR
5
+ PATCH = '0' unless defined? PATCH
6
6
  BETA = nil unless defined? BETA # Time.now.to_i.to_s
7
7
  end
8
8
 
@@ -135,7 +135,9 @@ end
135
135
  class Twurl::OAuthClient::PerformingRequestsFromOptionsTest < Twurl::OAuthClient::AbstractOAuthClientTest
136
136
  def test_request_is_made_using_request_method_and_path_and_data_in_options
137
137
  client = Twurl::OAuthClient.test_exemplar
138
- mock(client).get(options.path, options.data)
138
+ mock(client.consumer.http).request(satisfy { |req|
139
+ req.is_a?(Net::HTTP::Get) && (req.path == options.path)
140
+ })
139
141
 
140
142
  client.perform_request_from_options(options)
141
143
  end
@@ -41,8 +41,8 @@ class Twurl::RequestController::RequestTest < Twurl::RequestController::Abstract
41
41
  def test_request_response_is_written_to_output
42
42
  expected_body = 'this is a fake response body'
43
43
  response = Object.new
44
- mock(response).body.times(1) { expected_body }
45
- mock(client).perform_request_from_options(options).times(1) { response }
44
+ mock(response).read_body { |block| block.call expected_body }
45
+ mock(client).perform_request_from_options(options).times(1) { |options, block| block.call(response) }
46
46
 
47
47
  controller.perform_request
48
48
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twurl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-28 00:00:00.000000000 Z
13
+ date: 2012-05-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: oauth
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: 1.3.6
163
163
  requirements: []
164
164
  rubyforge_project: twurl
165
- rubygems_version: 1.8.23
165
+ rubygems_version: 1.8.24
166
166
  signing_key:
167
167
  specification_version: 3
168
168
  summary: Curl for the Twitter API