oauth-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+
2
+ 0.0.1
3
+ ---------------------------
4
+ initial release
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ CHANGELOG
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ bin/oauthc
6
+ init.rb
7
+ lib/oauth_cli.rb
data/README.rdoc ADDED
@@ -0,0 +1,62 @@
1
+ = oauth-cli
2
+ a simple CLI client to test your oauth API easily
3
+
4
+ == Installation
5
+ oauth-cli is packed as gem, install with:
6
+ gem install oauth-cli
7
+
8
+
9
+ == Usage
10
+ [repl] oauthc [options] <method> <uri> [<body>]
11
+
12
+ options may be:
13
+ * profile: --profile=<profile> -> put a .yml file to ~/.oauthconfig
14
+ * connection data: --host=<host> --consumer_key=<consumer_key> --consumer_secret=<consumer_secret> --token=<token> --token_secret=<token_secret>
15
+ * if method it *post* or *put* and no body is provided, you're asked for input
16
+
17
+
18
+ == Examples
19
+ oauthc was originally developed to test the {Qype API}[http://www.qype.com/developers/api]. Run these examples agains it:
20
+
21
+ post /feedbacks '<feedback><link href="http://api.qype.com/v1/reviews/66" rel="http://schemas.qype.com/review"/><comment><![CDATA[This review contains offending text]]></comment></feedback>'
22
+ post /places/31/checkins '<checkins><point>53.5505,9.93631</point></checkins>'
23
+ get /positions/53.55224,9.999/recommended_places
24
+ get /locators/de600-hamburg/feed
25
+ get /badges
26
+ get /users/tobiasb/badges
27
+ get /places/31.json?expand=popular_checkins
28
+
29
+
30
+ == Hints
31
+ * use with repl gem for nice handling, see http://github.com/defunkt/repl
32
+ * make sure to have rlwrap installed, too: http://utopia.knoware.nl/~hlub/rlwrap1
33
+
34
+
35
+ == Todos
36
+ * save given keys to config
37
+
38
+
39
+ == FAQ
40
+
41
+ ==== What's the difference to the client provided by oauth gem?
42
+ problem with oauth cli client provided with the gem is the lack of post request with body content as well as easy usage with repl to have proper CLI options
43
+
44
+
45
+ == Copyright
46
+ The MIT License
47
+
48
+ Copyright © 2010 RngTng, Tobias Bielohlawek
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
55
+
56
+
57
+ == More
58
+ Easy way to create your gem:
59
+ * http://buzaz.com/index.php/2010/01/03/how-to-build-a-ruby-gem
60
+ * http://railscasts.com/episodes/135-making-a-gem
61
+ * http://docs.rubygems.org/read/chapter/20
62
+ * http://rubygems.org
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('oauth-cli', '0.0.1') do |p|
6
+ p.description = "A simple CLI client to test your oauth API easily"
7
+ p.url = "http://github.com/rngtng/oauth-cli"
8
+ p.author = "rngtng - Tobias Bielohlawek"
9
+ p.email = "tobi @nospam@ rngtng.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ p.runtime_dependencies = ["highline >=1.5.1", "json >=1.1.9", "oauth >=0.3.6", "repl >=0.2.1"]
13
+ end
data/bin/oauthc ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'oauth_cli'
5
+
6
+ OauthCli.main($*)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'oauth_cli'
data/lib/oauth_cli.rb ADDED
@@ -0,0 +1,90 @@
1
+ require 'highline/import'
2
+ require 'oauth'
3
+ require 'json'
4
+
5
+ CFG_FILE = File.expand_path('~/.oauthconfig')
6
+ HighLine.track_eof = false #hotfix to make highline work
7
+
8
+ class OauthCli
9
+ def self.main(params, opt = {})
10
+ #parse CLI input
11
+ method, uri, body = params.delete_if do |kv|
12
+ next opt[$1.to_sym] = $2 if kv =~ /-?-([^=]+)=(.+)$/
13
+ false
14
+ end
15
+ body = ask ">> request body:" if body.to_s.empty? && (method == "post" || method == "put")
16
+ opt[:profile] ||= opt[:p] #shortcut for profile
17
+
18
+ #load external config if profile given
19
+ if opt[:profile] && File.exists?(CFG_FILE)
20
+ cfg_options = YAML.load_file(CFG_FILE)
21
+ opt = symbolize_keys(cfg_options[opt[:profile]]) if cfg_options[opt[:profile]]
22
+ end
23
+
24
+ if opt[:h] || opt[:help] || method.to_s.empty? || uri.to_s.empty?
25
+ say " <%= color('# ERROR: please provide method and uri', RED) %>" if method.to_s.empty? || uri.to_s.empty?
26
+ say "Usage:"
27
+ say "[repl] oauthc [options] <method> <uri> [<body>]"
28
+ say "options are:"
29
+ say "profile: --profile=<profile> -> put a .yml file to ~/.oauthconfig"
30
+ say "--host=<host> --consumer_key=<consumer_key> --consumer_secret=<consumer_secret> --token=<token> --token_secret=<token_secret>"
31
+ return
32
+ end
33
+
34
+ response = execute(method, uri, body, opt)
35
+
36
+ header = response.header
37
+ color = (response.code.to_i < 400) ? 'GREEN' : 'RED'
38
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
39
+ say " <%= color('# Status: #{header.code} #{header.message} - calling #{opt[:host]}#{uri}', BOLD, #{color}) %>"
40
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
41
+
42
+ body = response.body
43
+ body = " <%= color('# #{$1.gsub("'", "")} ', RED) %>" if body =~ /<pre>(.+)<\/pre>/
44
+ body = JSON.pretty_generate(JSON.parse(body)) if uri =~ /.json/ rescue ''
45
+ say body
46
+ end
47
+
48
+ def self.execute(method, uri, body, options)
49
+ if options[:consumer_key].to_s.empty?
50
+ color = 'YELLOW'
51
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
52
+ say " <%= color('# no consumer_key provided, call the script with:', #{color}) %>"
53
+ say " <%= color('# oauthc --consumer_key=<consumer_key> --consumer_secret=<consumer_secret>', #{color}) %>"
54
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
55
+ #please get a key here: http://#{options[:host]}/api_consumers"
56
+ exit
57
+ end
58
+
59
+ @consumer = OAuth::Consumer.new(options[:consumer_key], options[:consumer_secret], :site => "http://#{options[:host]}")
60
+
61
+ if options[:token]
62
+ @access_token = OAuth::AccessToken.new(@consumer, options[:token], options[:token_secret])
63
+ elsif !options[:read_only]
64
+ #say "To authorize, go to:\n <%= color('http://#{options[:host].gsub('api.', 'www.')}/mobile/authorize?oauth_token=#{@request_token.token}', BOLD, UNDERLINE) %>\n\n"
65
+
66
+ @request_token = @consumer.get_request_token({}, "oauth_callback" => "oob")
67
+ color = 'YELLOW'
68
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
69
+ say " <%= color('# no access token found please provide verifier to for tokens:', #{color}) %>"
70
+ verifier = ask ">>"
71
+
72
+ @access_token = @request_token.get_access_token({}, "oauth_verifier" => verifier)
73
+ say " <%= color('# all done, recall the script with:', #{color}) %>"
74
+ say " <%= color('# oauthc --consumer_key=#{options[:consumer_key]} --consumer_secret=#{options[:consumer_secret]} --token=#{@consumer.token} --token_secret=#{@consumer.secret}', #{color}) %>"
75
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
76
+ exit
77
+ end
78
+
79
+ url = "http://#{options[:host]}#{uri}"
80
+
81
+ mime_type = (url =~ /\.json/) ? "application/json" : "application/xml"
82
+ @consumer.request(method, url, @access_token, {}, body, { 'Accept' => mime_type, 'Content-Type' => mime_type })
83
+ end
84
+
85
+ def self.symbolize_keys(hash)
86
+ new_hash = {}
87
+ hash.each { |key, value| new_hash[key.to_sym] = value }
88
+ new_hash
89
+ end
90
+ end
data/oauth-cli.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{oauth-cli}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["rngtng - Tobias Bielohlawek"]
9
+ s.cert_chain = ["/Users/tobiasb/.ssh/gem-public_cert.pem"]
10
+ s.date = %q{2010-04-09}
11
+ s.default_executable = %q{oauthc}
12
+ s.description = %q{A simple CLI client to test your oauth API easily}
13
+ s.email = %q{tobi @nospam@ rngtng.com}
14
+ s.executables = ["oauthc"]
15
+ s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "bin/oauthc", "lib/oauth_cli.rb"]
16
+ s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "bin/oauthc", "init.rb", "lib/oauth_cli.rb", "oauth-cli.gemspec"]
17
+ s.homepage = %q{http://github.com/rngtng/oauth-cli}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Oauth-cli", "--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{oauth-cli}
21
+ s.rubygems_version = %q{1.3.6}
22
+ s.signing_key = %q{/Users/tobiasb/.ssh/gem-private_key.pem}
23
+ s.summary = %q{A simple CLI client to test your oauth API easily}
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 3
28
+
29
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
30
+ s.add_runtime_dependency(%q<highline>, [">= 1.5.1"])
31
+ s.add_runtime_dependency(%q<json>, [">= 1.1.9"])
32
+ s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
33
+ s.add_runtime_dependency(%q<repl>, [">= 0.2.1"])
34
+ else
35
+ s.add_dependency(%q<highline>, [">= 1.5.1"])
36
+ s.add_dependency(%q<json>, [">= 1.1.9"])
37
+ s.add_dependency(%q<oauth>, [">= 0.3.6"])
38
+ s.add_dependency(%q<repl>, [">= 0.2.1"])
39
+ end
40
+ else
41
+ s.add_dependency(%q<highline>, [">= 1.5.1"])
42
+ s.add_dependency(%q<json>, [">= 1.1.9"])
43
+ s.add_dependency(%q<oauth>, [">= 0.3.6"])
44
+ s.add_dependency(%q<repl>, [">= 0.2.1"])
45
+ end
46
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth-cli
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - rngtng - Tobias Bielohlawek
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDLDCCAhSgAwIBAgIBADANBgkqhkiG9w0BAQUFADA8MQ0wCwYDVQQDDAR0b2Jp
19
+ MRYwFAYKCZImiZPyLGQBGRYGcm5ndG5nMRMwEQYKCZImiZPyLGQBGRYDY29tMB4X
20
+ DTEwMDQwODEzMDc1NloXDTExMDQwODEzMDc1NlowPDENMAsGA1UEAwwEdG9iaTEW
21
+ MBQGCgmSJomT8ixkARkWBnJuZ3RuZzETMBEGCgmSJomT8ixkARkWA2NvbTCCASIw
22
+ DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOQgVmWlfSVPQHPyBTvRkQWD0zIZ
23
+ Yyth8soHdR9YwvnurNKCLtRyRrOM01o/BeA2hp66FwrUYRospL+AgLSArGL7Tewg
24
+ 3hHZBs2MkcgLSPjhlKLvNUGhVl4OYRve4gzj3yDRnc3CQRtYO5LtOQUEbpfMFFTP
25
+ ZmoW9C2PAaWqFYaNB9tAt4yl/c5SCx8mrGFK4t76odFnxGbPqIqaejZfBlxBUZ1P
26
+ QeE01rVdgeuGecjrzykKsO0iV5Gn2a+KaLKbdSpsB/AFNxy2ONF9qMjaxW0tCS9X
27
+ eED3SYdNqESWnTRYxBYksPkIh4bcts2Z3RdGJ1sarAZ36uPlSZFMEIzqOHkCAwEA
28
+ AaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFD/sOAP6yzIS
29
+ 8NgV9Ef3LMP8Fe7EMA0GCSqGSIb3DQEBBQUAA4IBAQDG4I202iZw+tZFqjjNJIkc
30
+ Yu6vEYX9vqZNImm0u1I0GPwlV6mon2cY4CFBcYFGdtC5lvEWoh85epH6dS/dS3P0
31
+ mZcSbFa9041ng1g+JrRhHlLZhQDD60Ffcu5lwVxXSgCT31M2rVdWxCfvritz3ygC
32
+ boM9qEt6n9Ujo6vJw7n3FArEnfzy1EoZmxB/0TJdM4n+56HTU5GmNnIkttJkcA6w
33
+ O0bVuuTBYRtFBVTeEXbjUiynIitUoZwd55qvFaSmQCrKtzNDs8GTkWp3ynUHbNkq
34
+ I5mOkC+DmQeKRCyukHoWnysL5IyK+l7JEPymkOlNWkl006u5rNu/d7LJJW19+ZvC
35
+ -----END CERTIFICATE-----
36
+
37
+ date: 2010-04-09 00:00:00 +02:00
38
+ default_executable: oauthc
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: highline
42
+ prerelease: false
43
+ requirement: &id001 !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 1
49
+ - 5
50
+ - 1
51
+ version: 1.5.1
52
+ type: :runtime
53
+ version_requirements: *id001
54
+ - !ruby/object:Gem::Dependency
55
+ name: json
56
+ prerelease: false
57
+ requirement: &id002 !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 1
63
+ - 1
64
+ - 9
65
+ version: 1.1.9
66
+ type: :runtime
67
+ version_requirements: *id002
68
+ - !ruby/object:Gem::Dependency
69
+ name: oauth
70
+ prerelease: false
71
+ requirement: &id003 !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ - 3
78
+ - 6
79
+ version: 0.3.6
80
+ type: :runtime
81
+ version_requirements: *id003
82
+ - !ruby/object:Gem::Dependency
83
+ name: repl
84
+ prerelease: false
85
+ requirement: &id004 !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ - 2
92
+ - 1
93
+ version: 0.2.1
94
+ type: :runtime
95
+ version_requirements: *id004
96
+ description: A simple CLI client to test your oauth API easily
97
+ email: tobi @nospam@ rngtng.com
98
+ executables:
99
+ - oauthc
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - CHANGELOG
104
+ - README.rdoc
105
+ - bin/oauthc
106
+ - lib/oauth_cli.rb
107
+ files:
108
+ - CHANGELOG
109
+ - Manifest
110
+ - README.rdoc
111
+ - Rakefile
112
+ - bin/oauthc
113
+ - init.rb
114
+ - lib/oauth_cli.rb
115
+ - oauth-cli.gemspec
116
+ has_rdoc: true
117
+ homepage: http://github.com/rngtng/oauth-cli
118
+ licenses: []
119
+
120
+ post_install_message:
121
+ rdoc_options:
122
+ - --line-numbers
123
+ - --inline-source
124
+ - --title
125
+ - Oauth-cli
126
+ - --main
127
+ - README.rdoc
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ segments:
142
+ - 1
143
+ - 2
144
+ version: "1.2"
145
+ requirements: []
146
+
147
+ rubyforge_project: oauth-cli
148
+ rubygems_version: 1.3.6
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: A simple CLI client to test your oauth API easily
152
+ test_files: []
153
+
metadata.gz.sig ADDED
Binary file