twurl 0.9.1 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest DELETED
File without changes
data/.gitignore DELETED
@@ -1,38 +0,0 @@
1
- *.gem
2
- *.rbc
3
- *.sw[a-p]
4
- *.tmproj
5
- *.tmproject
6
- *.un~
7
- *~
8
- .Spotlight-V100
9
- .Trashes
10
- ._*
11
- .bundle
12
- .config
13
- .directory
14
- .elc
15
- .emacs.desktop
16
- .emacs.desktop.lock
17
- .redcar
18
- .yardoc
19
- Desktop.ini
20
- Gemfile.lock
21
- Icon?
22
- InstalledFiles
23
- Session.vim
24
- \#*\#
25
- _yardoc
26
- auto-save-list
27
- coverage
28
- doc
29
- lib/bundler/man
30
- pkg
31
- pkg/*
32
- rdoc
33
- spec/reports
34
- test/tmp
35
- test/version_tmp
36
- tmp
37
- tmtags
38
- tramp
@@ -1,16 +0,0 @@
1
- bundler_args: --without development
2
- language: ruby
3
- rvm:
4
- - 1.8.7
5
- - 1.9.2
6
- - 1.9.3
7
- - 2.0.0
8
- - jruby-head
9
- - rbx
10
- - ruby-head
11
- matrix:
12
- allow_failures:
13
- - rvm: jruby-head
14
- - rvm: rbx
15
- - rvm: ruby-head
16
- fast_finish: true
data/COPYING DELETED
@@ -1,18 +0,0 @@
1
- # Copyright (c) 2009 Marcel Molina <marcel@twitter.com>, Twitter, Inc.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the "Software"), to deal in the
5
- # Software without restriction, including without limitation the rights to use,
6
- # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- # Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17
- # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Gemfile DELETED
@@ -1,20 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'jruby-openssl', :platforms => :jruby
4
- gem 'rake'
5
-
6
- group :test do
7
- gem 'coveralls', :require => false
8
- gem 'mime-types', '~> 1.25', :platforms => :ruby_18
9
- gem 'minitest', '>= 5'
10
- gem 'rr', '>= 1.1'
11
- gem 'simplecov', :require => false
12
- end
13
-
14
- platforms :rbx do
15
- gem 'rubinius-coverage', '~> 2.0'
16
- gem 'rubysl-base64', '~> 2.0'
17
- gem 'rubysl-net-http', '~> 2.0'
18
- end
19
-
20
- gemspec
data/INSTALL DELETED
@@ -1,18 +0,0 @@
1
- +-----------------------+
2
- | Install with RubyGems |
3
- +-----------------------+
4
-
5
- sudo gem i twurl --source http://rubygems.org
6
-
7
- +---------------------+
8
- | Install from source |
9
- +---------------------+
10
-
11
- rake dist:gem
12
- sudo gem i pkg/twurl*gem
13
-
14
- +--------------+
15
- | Dependencies |
16
- +--------------+
17
-
18
- sudo gem i oauth
data/README DELETED
@@ -1,119 +0,0 @@
1
- +-------+
2
- | Twurl |
3
- +-------+
4
-
5
- Twurl is like curl, but tailored specifically for the Twitter API.
6
- It knows how to grant an access token to a client application for
7
- a specified user and then sign all requests with that access token.
8
-
9
- It also provides other development and debugging conveniences such
10
- as defining aliases for common requests, as well as support for
11
- multiple access tokens to easily switch between different client
12
- applications and Twitter accounts.
13
-
14
- +-----------------+
15
- | Getting Started |
16
- +-----------------+
17
-
18
- The first thing you have to do is register an OAuth application
19
- to get a consumer key and secret.
20
-
21
- http://dev.twitter.com/apps/new
22
-
23
- When you have your consumer key and its secret you authorize
24
- your Twitter account to make API requests with your consumer key
25
- and secret.
26
-
27
- % twurl authorize --consumer-key key \
28
- --consumer-secret secret
29
-
30
- This will return an URL that you should open up in your browser.
31
- Authenticate to Twitter, and then enter the returned PIN back into
32
- the terminal. Assuming all that works well, you will beauthorized
33
- to make requests with the API. Twurl will tell you as much.
34
-
35
- If your consumer application has xAuth enabled, then you can use
36
- a variant of the above
37
-
38
- % twurl authorize -u username -p password \
39
- --consumer-key key \
40
- --consumer-secret secret
41
-
42
- And, again assuming your username, password, key and secret is
43
- correct, will authorize you in one step.
44
-
45
- +-----------------+
46
- | Making Requests |
47
- +-----------------+
48
-
49
- The simplest request just requires that you specify the path you
50
- want to request.
51
-
52
- % twurl /1.1/statuses/home_timeline.json
53
-
54
- Similar to curl, a GET request is performed by default.
55
-
56
- You can implicitly perform a POST request by passing the -d option,
57
- which specifies POST parameters.
58
-
59
- % twurl -d 'status=Testing twurl' /1.1/statuses/update.json
60
-
61
- You can explicitly specify what request method to perform with
62
- the -X (or --request-method) option.
63
-
64
- % twurl -X POST /1.1/statuses/destroy/1234567890.json
65
-
66
- +------------------+
67
- | Creating aliases |
68
- +------------------+
69
-
70
- % twurl alias h /1.1/statuses/home_timeline.json
71
-
72
- You can then use "h" in place of the full path.
73
-
74
- % twurl h
75
-
76
- Paths that require additional options such as request parameters for example can
77
- be used with aliases the same as with full explicit paths, just as you might
78
- expect.
79
-
80
- % twurl alias tweet /1.1/statuses/update.json
81
- % twurl tweet -d "status=Aliases in twurl are convenient"
82
-
83
- +-------------------------------+
84
- | Changing your default profile |
85
- +-------------------------------+
86
-
87
- The first time you authorize a client application to make requests on behalf of your account, twurl stores your access token information in its .twurlrc file. Subsequent requests will use this profile as the default profile. You can use the 'accounts' subcommand to see what client applications have been authorized for what user names:
88
-
89
- % twurl accounts
90
- noradio
91
- HQsAGcBm5MQT4n6j7qVJw
92
- hhC7Koy2zRsTZvQh1hVlSA (default)
93
- testiverse
94
- guT9RsJbNQgVe6AwoY9BA
95
-
96
- Notice that one of those consumer keys is marked as the default. To change the default use the 'set' subcommand, passing then either just the username, if it's unambiguous, or the username and consumer key pair if it isn't unambiguous:
97
-
98
- % twurl set default testiverse
99
- % twurl accounts
100
- noradio
101
- HQsAGcBm5MQT4n6j7qVJw
102
- hhC7Koy2zRsTZvQh1hVlSA
103
- testiverse
104
- guT9RsJbNQgVe6AwoY9BA (default)
105
-
106
- % twurl set default noradio HQsAGcBm5MQT4n6j7qVJw
107
- % twurl accounts
108
- noradio
109
- HQsAGcBm5MQT4n6j7qVJw (default)
110
- hhC7Koy2zRsTZvQh1hVlSA
111
- testiverse
112
- guT9RsJbNQgVe6AwoY9BA
113
-
114
- +--------------+
115
- | Contributors |
116
- +--------------+
117
-
118
- Marcel Molina <marcel@twitter.com> / @noradio
119
- Erik Michaels-Ober / @sferik
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- require 'rake/testtask'
2
- require 'rubygems/package_task'
3
- require 'bundler'
4
-
5
- task :default => :test
6
-
7
- Rake::TestTask.new do |test|
8
- test.pattern = 'test/*_test.rb'
9
- test.verbose = true
10
- end
11
-
12
- Bundler::GemHelper.install_tasks
@@ -1,61 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class Twurl::AccountInformationController::DispatchWithNoAuthorizedAccountsTest < Minitest::Test
4
- attr_reader :options, :client, :controller
5
- def setup
6
- @options = Twurl::Options.new
7
- @client = Twurl::OAuthClient.load_new_client_from_options(options)
8
- @controller = Twurl::AccountInformationController.new(client, options)
9
- mock(Twurl::OAuthClient.rcfile).empty? { true }
10
- end
11
-
12
- def test_message_indicates_when_no_accounts_are_authorized
13
- mock(Twurl::CLI).puts(Twurl::AccountInformationController::NO_AUTHORIZED_ACCOUNTS_MESSAGE).times(1)
14
-
15
- controller.dispatch
16
- end
17
- end
18
-
19
- class Twurl::AccountInformationController::DispatchWithOneAuthorizedAccountTest < Minitest::Test
20
- attr_reader :options, :client, :controller
21
- def setup
22
- @options = Twurl::Options.test_exemplar
23
- @client = Twurl::OAuthClient.load_new_client_from_options(options)
24
- mock(Twurl::OAuthClient.rcfile).save.times(1)
25
- Twurl::OAuthClient.rcfile << client
26
- @controller = Twurl::AccountInformationController.new(client, options)
27
- end
28
-
29
- def test_authorized_account_is_displayed_and_marked_as_the_default
30
- mock(Twurl::CLI).puts(client.username).times(1).ordered
31
- mock(Twurl::CLI).puts(" #{client.consumer_key} (default)").times(1).ordered
32
-
33
- controller.dispatch
34
- end
35
- end
36
-
37
- class Twurl::AccountInformationController::DispatchWithOneUsernameThatHasAuthorizedMultipleAccountsTest < Minitest::Test
38
- attr_reader :default_client_options, :default_client, :other_client_options, :other_client, :controller
39
- def setup
40
- @default_client_options = Twurl::Options.test_exemplar
41
- @default_client = Twurl::OAuthClient.load_new_client_from_options(default_client_options)
42
-
43
- @other_client_options = Twurl::Options.test_exemplar
44
- other_client_options.consumer_key = default_client_options.consumer_key.reverse
45
- @other_client = Twurl::OAuthClient.load_new_client_from_options(other_client_options)
46
- mock(Twurl::OAuthClient.rcfile).save.times(2)
47
-
48
- Twurl::OAuthClient.rcfile << default_client
49
- Twurl::OAuthClient.rcfile << other_client
50
-
51
- @controller = Twurl::AccountInformationController.new(other_client, other_client_options)
52
- end
53
-
54
- def test_authorized_account_is_displayed_and_marked_as_the_default
55
- mock(Twurl::CLI).puts(default_client.username).times(1)
56
- mock(Twurl::CLI).puts(" #{default_client.consumer_key} (default)").times(1)
57
- mock(Twurl::CLI).puts(" #{other_client.consumer_key}").times(1)
58
-
59
- controller.dispatch
60
- end
61
- end
@@ -1,53 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class Twurl::AliasesController::DispatchTest < Minitest::Test
4
- attr_reader :options, :client
5
- def setup
6
- @options = Twurl::Options.test_exemplar
7
- @client = Twurl::OAuthClient.test_exemplar
8
-
9
- # Clean slate
10
- if Twurl::OAuthClient.rcfile.aliases
11
- Twurl::OAuthClient.rcfile.aliases.clear
12
- end
13
-
14
- stub(Twurl::OAuthClient.rcfile).save
15
- end
16
-
17
- def test_when_no_subcommands_are_provided_and_no_aliases_exist_nothing_is_displayed
18
- assert options.subcommands.empty?
19
- mock(Twurl::CLI).puts(Twurl::AliasesController::NO_ALIASES_MESSAGE).times(1)
20
-
21
- controller = Twurl::AliasesController.new(client, options)
22
- controller.dispatch
23
- end
24
-
25
- def test_when_no_subcommands_are_provided_and_aliases_exist_they_are_displayed
26
- assert options.subcommands.empty?
27
-
28
- Twurl::OAuthClient.rcfile.alias('h', '/1.1/statuses/home_timeline.json')
29
- mock(Twurl::CLI).puts("h: /1.1/statuses/home_timeline.json").times(1)
30
-
31
- controller = Twurl::AliasesController.new(client, options)
32
- controller.dispatch
33
- end
34
-
35
- def test_when_alias_and_value_are_provided_they_are_added
36
- options.subcommands = ['h']
37
- options.path = '/1.1/statuses/home_timeline.json'
38
- mock(Twurl::OAuthClient.rcfile).alias('h', '/1.1/statuses/home_timeline.json').times(1)
39
-
40
- controller = Twurl::AliasesController.new(client, options)
41
- controller.dispatch
42
- end
43
-
44
- def test_when_no_path_is_provided_nothing_happens
45
- options.subcommands = ['a']
46
- assert_nil options.path
47
-
48
- mock(Twurl::CLI).puts(Twurl::AliasesController::NO_PATH_PROVIDED_MESSAGE).times(1)
49
-
50
- controller = Twurl::AliasesController.new(client, options)
51
- controller.dispatch
52
- end
53
- end
@@ -1,30 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class Twurl::AuthorizationController::DispatchTest < Minitest::Test
4
- attr_reader :options, :client, :controller
5
- def setup
6
- @options = Twurl::Options.new
7
- @client = Twurl::OAuthClient.load_new_client_from_options(options)
8
- @controller = Twurl::AuthorizationController.new(client, options)
9
- end
10
-
11
- def test_successful_authentication_saves_retrieved_access_token
12
- mock(client).exchange_credentials_for_access_token.times(1)
13
- mock(client).save.times(1)
14
- mock(controller).raise(Twurl::Exception, Twurl::AuthorizationController::AUTHORIZATION_FAILED_MESSAGE).never
15
- mock(Twurl::CLI).puts(Twurl::AuthorizationController::AUTHORIZATION_SUCCEEDED_MESSAGE).times(1)
16
-
17
- controller.dispatch
18
- end
19
-
20
- module ErrorCases
21
- def test_failed_authorization_does_not_save_client
22
- mock(client).exchange_credentials_for_access_token { raise OAuth::Unauthorized }
23
- mock(client).save.never
24
- mock(controller).raise(Twurl::Exception, Twurl::AuthorizationController::AUTHORIZATION_FAILED_MESSAGE).times(1)
25
-
26
- controller.dispatch
27
- end
28
- end
29
- include ErrorCases
30
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class Twurl::Options::Test < Minitest::Test
4
- attr_reader :options
5
- def setup
6
- @options = Twurl::Options.new
7
- end
8
-
9
- def test_base_url_is_built_from_protocol_and_host
10
- options.protocol = 'http'
11
- options.host = 'api.twitter.com'
12
-
13
- assert_equal 'http://api.twitter.com', options.base_url
14
- end
15
-
16
- def test_ssl_is_enabled_if_the_protocol_is_https
17
- options.protocol = 'http'
18
- assert !options.ssl?
19
-
20
- options.protocol = 'https'
21
- assert options.ssl?
22
- end
23
- end
@@ -1,192 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class Twurl::CLI::OptionParsingTest < Minitest::Test
4
- TEST_PATH = '/1.1/url/does/not/matter.json'
5
-
6
- module CommandParsingTests
7
- def test_no_command_specified_falls_to_default_command
8
- options = Twurl::CLI.parse_options([TEST_PATH])
9
- assert_equal Twurl::CLI::DEFAULT_COMMAND, options.command
10
- end
11
-
12
- def test_supported_command_specified_extracts_the_command
13
- expected_command = Twurl::CLI::SUPPORTED_COMMANDS.first
14
- options = Twurl::CLI.parse_options([expected_command])
15
- assert_equal expected_command, options.command
16
- end
17
-
18
- def test_unsupported_command_specified_sets_default_command
19
- unsupported_command = 'unsupported'
20
- options = Twurl::CLI.parse_options([TEST_PATH, unsupported_command])
21
- assert_equal Twurl::CLI::DEFAULT_COMMAND, options.command
22
- end
23
- end
24
- include CommandParsingTests
25
-
26
- module PathParsingTests
27
- def test_missing_path_throws_no_path_found
28
- stub(Twurl::CLI).puts
29
- assert_raises Twurl::CLI::NoPathFound do
30
- Twurl::CLI.parse_options([])
31
- end
32
- end
33
-
34
- def test_uri_params_are_encoded
35
- options = Twurl::CLI.parse_options(["/1.1/url?baz=bamf:rofl"])
36
- assert_equal options.path, "/1.1/url?baz=bamf%3Arofl"
37
- end
38
- end
39
- include PathParsingTests
40
-
41
- module RequestMethodParsingTests
42
- def test_request_method_is_default_if_unspecified
43
- options = Twurl::CLI.parse_options([TEST_PATH])
44
- assert_equal Twurl::Options::DEFAULT_REQUEST_METHOD, options.request_method
45
- end
46
-
47
- def test_specifying_a_request_method_extracts_and_normalizes_request_method
48
- variations = [%w[-X put], %w[-X PUT], %w[--request-method PUT], %w[--request-method put]]
49
- variations.each do |option_variation|
50
- order_variant_1 = [option_variation, TEST_PATH].flatten
51
- order_variant_2 = [TEST_PATH, option_variation].flatten
52
- [order_variant_1, order_variant_2].each do |args|
53
- options = Twurl::CLI.parse_options(args)
54
- assert_equal 'put', options.request_method
55
- end
56
- end
57
- end
58
-
59
- def test_specifying_unsupported_request_method_returns_an_error
60
- Twurl::CLI.parse_options([TEST_PATH, '-X', 'UNSUPPORTED'])
61
- end
62
- end
63
- include RequestMethodParsingTests
64
-
65
- module OAuthClientOptionParsingTests
66
- def test_extracting_the_consumer_key
67
- mock(Twurl::CLI).prompt_for('Consumer key').never
68
-
69
- options = Twurl::CLI.parse_options([TEST_PATH, '-c', 'the-key'])
70
- assert_equal 'the-key', options.consumer_key
71
- end
72
-
73
- def test_consumer_key_option_with_no_value_prompts_user_for_value
74
- mock(Twurl::CLI).prompt_for('Consumer key').times(1) { 'inputted-key'}
75
- options = Twurl::CLI.parse_options([TEST_PATH, '-c'])
76
- assert_equal 'inputted-key', options.consumer_key
77
- end
78
- end
79
- include OAuthClientOptionParsingTests
80
-
81
- module DataParsingTests
82
- def test_extracting_a_single_key_value_pair
83
- options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value'])
84
- assert_equal({'key' => 'value'}, options.data)
85
-
86
- options = Twurl::CLI.parse_options([TEST_PATH, '--data', 'key=value'])
87
- assert_equal({'key' => 'value'}, options.data)
88
- end
89
-
90
- def test_passing_data_and_no_explicit_request_method_defaults_request_method_to_post
91
- options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value'])
92
- assert_equal 'post', options.request_method
93
- end
94
-
95
- def test_passing_data_and_an_explicit_request_method_uses_the_specified_method
96
- options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value', '-X', 'DELETE'])
97
- assert_equal({'key' => 'value'}, options.data)
98
- assert_equal 'delete', options.request_method
99
- end
100
-
101
- def test_multiple_pairs_when_option_is_specified_multiple_times_on_command_line_collects_all
102
- options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value', '-d', 'another=pair'])
103
- assert_equal({'key' => 'value', 'another' => 'pair'}, options.data)
104
- end
105
-
106
- def test_multiple_pairs_separated_by_ampersand_are_all_captured
107
- options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key=value&another=pair'])
108
- assert_equal({'key' => 'value', 'another' => 'pair'}, options.data)
109
- end
110
-
111
- def test_extracting_an_empty_key_value_pair
112
- options = Twurl::CLI.parse_options([TEST_PATH, '-d', 'key='])
113
- assert_equal({'key' => ''}, options.data)
114
-
115
- options = Twurl::CLI.parse_options([TEST_PATH, '--data', 'key='])
116
- assert_equal({'key' => ''}, options.data)
117
- end
118
- end
119
- include DataParsingTests
120
-
121
- module HeaderParsingTests
122
- def test_extracting_a_single_header
123
- options = Twurl::CLI.parse_options([TEST_PATH, '-A', 'Key: Value'])
124
- assert_equal({'Key' => 'Value'}, options.headers)
125
-
126
- options = Twurl::CLI.parse_options([TEST_PATH, '--header', 'Key: Value'])
127
- assert_equal({'Key' => 'Value'}, options.headers)
128
- end
129
-
130
- def test_multiple_headers_when_option_is_specified_multiple_times_on_command_line_collects_all
131
- options = Twurl::CLI.parse_options([TEST_PATH, '-A', 'Key: Value', '-A', 'Another: Pair'])
132
- assert_equal({'Key' => 'Value', 'Another' => 'Pair'}, options.headers)
133
- end
134
- end
135
- include HeaderParsingTests
136
-
137
- module SSLDisablingTests
138
- def test_ssl_is_on_by_default
139
- options = Twurl::CLI.parse_options([TEST_PATH])
140
- assert options.ssl?
141
- end
142
-
143
- def test_passing_no_ssl_option_disables_ssl
144
- ['-U', '--no-ssl'].each do |switch|
145
- options = Twurl::CLI.parse_options([TEST_PATH, switch])
146
- assert !options.ssl?
147
- end
148
- end
149
- end
150
- include SSLDisablingTests
151
-
152
- module HostOptionTests
153
- def test_not_specifying_host_sets_it_to_the_default
154
- options = Twurl::CLI.parse_options([TEST_PATH])
155
- assert_equal Twurl::Options::DEFAULT_HOST, options.host
156
- end
157
-
158
- def test_setting_host_updates_to_requested_value
159
- custom_host = 'localhost:3000'
160
- assert Twurl::Options::DEFAULT_HOST != custom_host
161
-
162
- [[TEST_PATH, '-H', custom_host], [TEST_PATH, '--host', custom_host]].each do |option_combination|
163
- options = Twurl::CLI.parse_options(option_combination)
164
- assert_equal custom_host, options.host
165
- end
166
- end
167
-
168
- def test_protocol_is_stripped_from_host
169
- custom_host = 'localhost:3000'
170
- options = Twurl::CLI.parse_options([TEST_PATH, '-H', "https://"+custom_host])
171
- assert_equal custom_host, options.host
172
- end
173
- end
174
- include HostOptionTests
175
-
176
- module ProxyOptionTests
177
- def test_not_specifying_proxy_sets_it_to_nil
178
- options = Twurl::CLI.parse_options([TEST_PATH])
179
- assert_equal nil, options.proxy
180
- end
181
-
182
- def test_setting_proxy_updates_to_requested_value
183
- custom_proxy = 'localhost:80'
184
-
185
- [[TEST_PATH, '-P', custom_proxy], [TEST_PATH, '--proxy', custom_proxy]].each do |option_combination|
186
- options = Twurl::CLI.parse_options(option_combination)
187
- assert_equal custom_proxy, options.proxy
188
- end
189
- end
190
- end
191
- include ProxyOptionTests
192
- end