oauth-cli 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,12 +1,19 @@
1
- // planned: 0.0.4
1
+ // planned: 0.0.X
2
2
  // ---------------------------
3
3
  // on exit, ask if connection data should be saved to profile
4
4
  // show list of example profiles
5
5
 
6
+ 0.0.4
7
+ ---------------------------
8
+ introduced easy auth (by now for Qype API only)
9
+ added tests
10
+ "http://" for any host options got optional
11
+
6
12
  0.0.3
7
13
  ---------------------------
8
14
  minor fix to resolve dependencies
9
15
 
16
+
10
17
  0.0.2
11
18
  ---------------------------
12
19
  got rid of repl dependency
data/Manifest CHANGED
@@ -3,6 +3,8 @@ Manifest
3
3
  README.rdoc
4
4
  Rakefile
5
5
  bin/oauthc
6
- init.rb
7
6
  lib/oauth_cli.rb
8
7
  oauth-cli.gemspec
8
+ test/helper.rb
9
+ test/test_oauth_cli.rb
10
+ test/test_oauthc.rb
data/README.rdoc CHANGED
@@ -30,13 +30,13 @@ Request params (leave blank for interactive mode)
30
30
  if no request params are specified, interactive mode is started. Those commands are available:
31
31
 
32
32
  Interactive Commands:
33
- get uri Get request for given uri
34
- post uri [body] Post request for given uri, asks for body if not provided
35
- put uri [body] Put request for given uri, asks for body if not provided
36
- delete uri Delete request for given uri
33
+ get uri Get request for given uri
34
+ post uri [body] Post request for given uri, asks for body if not provided
35
+ put uri [body] Put request for given uri, asks for body if not provided
36
+ delete uri Delete request for given uri
37
37
 
38
- auth Request authentication token
39
- help Display this message
38
+ auth Request authentication token
39
+ help Display this message
40
40
 
41
41
 
42
42
  == Examples
@@ -52,18 +52,19 @@ oauthc was originally developed to test the {Qype API}[http://www.qype.com/devel
52
52
 
53
53
 
54
54
  == Hints
55
- * use with repl gem for nice handling, see: http://github.com/defunkt/repl
56
- * make sure to have rlwrap installed, too: http://utopia.knoware.nl/~hlub/rlwrap1
55
+ * make sure to have rlwrap installed, to get CLI history support: http://utopia.knoware.nl/~hlub/rlwrap (or "port install rlwarp")
56
+
57
+
57
58
  * Bug reports, suggestions, updates: http://github.com/rngtng/oauth-cli/issues
58
59
 
59
60
 
60
61
  == Todos
61
- * save given keys to config, e-g introduce 'save' command
62
+ * save given keys to config, e.g. introduce 'save' command
62
63
  * go into config mode, if no profiles found and no params specified
63
64
  * better support for getting authkeys
64
65
  * testing + better docs
65
66
  * check oauth client, streamline!?
66
- * add autocomplete
67
+ * add autocomplete for interactive commands
67
68
  * add auth profiles for Qype, Twitter etc!?
68
69
 
69
70
  == FAQ
data/Rakefile CHANGED
@@ -2,12 +2,12 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('oauth-cli', '0.0.3') do |p|
5
+ Echoe.new('oauth-cli', '0.0.4') do |p|
6
6
  p.description = "A simple CLI client to test your oauth API easily"
7
7
  p.url = "http://github.com/rngtng/oauth-cli"
8
8
  p.author = "rngtng - Tobias Bielohlawek"
9
9
  p.email = "tobi @nospam@ rngtng.com"
10
10
  p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = []
11
+ p.development_dependencies = ["mocha >=0"]
12
12
  p.runtime_dependencies = ["highline >=1.5.1", "json >=1.1.9", "oauth >=0.3.6"]
13
13
  end
data/bin/oauthc CHANGED
@@ -2,13 +2,19 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'pp'
5
- require 'oauth_cli'
5
+ begin
6
+ require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/lib/oauth_cli"
7
+ rescue LoadError
8
+ require "oauth_cli"
9
+ end
6
10
 
7
11
  CFG_FILE = ENV['OAUTHC_CONFIG_FILE'] || File.expand_path('~/.oauthconfig')
8
12
 
13
+ #http://api.betterbecool.com/v1/places/1197081
14
+
9
15
  def show_help
10
16
  say <<-help
11
- oauthc version 0.0.3
17
+ oauthc version 0.0.4
12
18
  Usage: oauthc [options] [http_method_verb uri [body]]
13
19
 
14
20
  Options:
@@ -101,7 +107,7 @@ history_dir = ENV['OAUTHC_HISTORY_DIR'] || "~/"
101
107
  if File.exists?(hdir = File.expand_path(history_dir))
102
108
  if script = ARGV.detect { |a| a !~ /^-/ }
103
109
  script = File.basename(script)
104
- hfile = "#{hdir}/.#{oauthc}_history" #TODO include profile name???
110
+ hfile = "#{hdir}/.oauthc_history" #TODO include profile name???
105
111
  end
106
112
  end
107
113
 
@@ -131,7 +137,7 @@ loop do
131
137
  #save_config unless profile
132
138
  puts
133
139
  exit
134
- rescue
140
+ #rescue
135
141
  end
136
142
 
137
143
  end
data/lib/oauth_cli.rb CHANGED
@@ -3,16 +3,18 @@ require 'oauth'
3
3
  require 'json'
4
4
 
5
5
  begin
6
- require 'ap'
7
- rescue LoadError
6
+ require 'ap' #try to load awesome_print for nice json output
7
+ rescue LoadError
8
8
  end
9
9
 
10
10
  HighLine.track_eof = false #hotfix to make highline work
11
11
 
12
12
  class OauthCli
13
13
 
14
- def initialize( options = {})
15
- @options = options
14
+ attr_reader :options
15
+
16
+ def initialize(options = {})
17
+ @options = options
16
18
 
17
19
  if options[:consumer_key].to_s.empty?
18
20
  color = 'YELLOW'
@@ -20,28 +22,46 @@ class OauthCli
20
22
  say " <%= color('# no consumer_key provided, please create a profile or call the script with:', #{color}) %>"
21
23
  say " <%= color('# oauthc --consumer_key=<consumer_key> --consumer_secret=<consumer_secret>', #{color}) %>"
22
24
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
23
- #please get a key here: http://#{options[:host]}/api_consumers"
24
- exit
25
+ #please get a key here: #{options[:host]}/api_consumers"
26
+ return
25
27
  end
26
-
27
- @consumer = OAuth::Consumer.new(options[:consumer_key], options[:consumer_secret], :site => "http://#{options[:host]}")
28
- @access_token = OAuth::AccessToken.new(@consumer, options[:token], options[:token_secret]) if options[:token]
28
+
29
+ #add http if missing
30
+ [:host, :reg_host, :auth_host].each do |key|
31
+ @options[key] = "http://#{@options[key]}" unless @options[key] =~ /^http/
32
+ end
33
+
34
+ @consumer = OAuth::Consumer.new(@options[:consumer_key], @options[:consumer_secret], :site => @options[:host])
35
+ @access_token = OAuth::AccessToken.new(@consumer, @options[:token], @options[:token_secret]) if @options[:token]
29
36
  end
30
37
 
31
38
  def request(method, uri, body = nil)
32
39
  if method =~ /auth/
33
40
  @request_token = @consumer.get_request_token({}, "oauth_callback" => "oob")
41
+ @options[:auth_host] ||= "#{@options[:host].gsub('api.', 'www.').gsub('v1/', '')}/mobile/authorize?oauth_token=" #That's for Qype only!!
34
42
  color = 'YELLOW'
35
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
36
- #say "To authorize, go to:\n <%= color('http://#{options[:host].gsub('api.', 'www.')}/mobile/authorize?oauth_token=#{@request_token.token}', BOLD, UNDERLINE) %>\n\n"
37
- verifier = ask " Token Verifier >>"
38
-
39
- @access_token = @request_token.get_access_token({}, "oauth_verifier" => verifier)
40
-
41
- options[:token] = @access_token.token
42
- options[:token_secret] = @access_token.secret
43
-
44
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
43
+ say " <%= color('# To authorize, go to ...', #{color}) %>"
44
+ say " <%= '# ' + color('#{@options[:auth_host]}#{@request_token.token}', BOLD, UNDERLINE) %>\n"
45
+ say " <%= color('# ... and enter given token verifier:', #{color}) %>"
46
+ verifier = ask " |-- verifier >> "
47
+
48
+ begin
49
+ @access_token = @request_token.get_access_token({}, "oauth_verifier" => verifier)
50
+
51
+ @options[:token] = @access_token.token
52
+ @options[:token_secret] = @access_token.secret
53
+
54
+ color = 'GREEN'
55
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
56
+ say " <%= color('# Authorization SUCCESSFUL', BOLD, #{color}) %>"
57
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
58
+ rescue
59
+ color = 'RED'
60
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
61
+ say " <%= color('# Authorization FAILED', BOLD, #{color}) %>"
62
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
63
+ end
64
+ return
45
65
  end
46
66
 
47
67
  unless %w(get post put delete).include? method.to_s
@@ -54,8 +74,8 @@ class OauthCli
54
74
 
55
75
  uri = ask " |-- request uri >> " if !uri
56
76
  body = ask " |-- request body >> " if !body && (method == "post" || method == "put")
57
-
58
- url = "http://#{@options[:host]}#{uri}"
77
+
78
+ url = @options[:host] + uri
59
79
 
60
80
  @options[:mime_type] ||= (url =~ /\.json/) ? "application/json" : "application/xml"
61
81
  @options[:content_type] ||= (url =~ /\.json/) ? "application/json" : "application/xml"
@@ -70,15 +90,14 @@ class OauthCli
70
90
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
71
91
 
72
92
  body = response.body
73
- if header.content_type =~ /.json/
93
+ if header.content_type =~ /json/
74
94
  body = JSON.parse(body)
75
95
  ap(body) rescue say(JSON.pretty_generate(body))
76
96
  return
77
97
  end
78
-
98
+
79
99
  body = " <%= color('# #{$1.gsub("'", "")} ', RED) %>" if body =~ /<pre>(.+)<\/pre>/
80
100
  say body
81
101
  end
82
102
 
83
-
84
103
  end
data/oauth-cli.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{oauth-cli}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["rngtng - Tobias Bielohlawek"]
9
9
  s.cert_chain = ["/Users/tobiasb/.ssh/gem-public_cert.pem"]
10
- s.date = %q{2010-04-20}
10
+ s.date = %q{2010-04-23}
11
11
  s.default_executable = %q{oauthc}
12
12
  s.description = %q{A simple CLI client to test your oauth API easily}
13
13
  s.email = %q{tobi @nospam@ rngtng.com}
14
14
  s.executables = ["oauthc"]
15
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"]
16
+ s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "bin/oauthc", "lib/oauth_cli.rb", "oauth-cli.gemspec", "test/helper.rb", "test/test_oauth_cli.rb", "test/test_oauthc.rb"]
17
17
  s.homepage = %q{http://github.com/rngtng/oauth-cli}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Oauth-cli", "--main", "README.rdoc"]
19
19
  s.require_paths = ["lib"]
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.rubygems_version = %q{1.3.6}
22
22
  s.signing_key = %q{/Users/tobiasb/.ssh/gem-private_key.pem}
23
23
  s.summary = %q{A simple CLI client to test your oauth API easily}
24
+ s.test_files = ["test/test_oauth_cli.rb", "test/test_oauthc.rb"]
24
25
 
25
26
  if s.respond_to? :specification_version then
26
27
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -30,14 +31,17 @@ Gem::Specification.new do |s|
30
31
  s.add_runtime_dependency(%q<highline>, [">= 1.5.1"])
31
32
  s.add_runtime_dependency(%q<json>, [">= 1.1.9"])
32
33
  s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
34
+ s.add_development_dependency(%q<mocha>, [">= 0"])
33
35
  else
34
36
  s.add_dependency(%q<highline>, [">= 1.5.1"])
35
37
  s.add_dependency(%q<json>, [">= 1.1.9"])
36
38
  s.add_dependency(%q<oauth>, [">= 0.3.6"])
39
+ s.add_dependency(%q<mocha>, [">= 0"])
37
40
  end
38
41
  else
39
42
  s.add_dependency(%q<highline>, [">= 1.5.1"])
40
43
  s.add_dependency(%q<json>, [">= 1.1.9"])
41
44
  s.add_dependency(%q<oauth>, [">= 0.3.6"])
45
+ s.add_dependency(%q<mocha>, [">= 0"])
42
46
  end
43
47
  end
data/test/helper.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'oauth_cli'
8
+
9
+ class Test::Unit::TestCase
10
+ end
11
+
12
+ #mock oauth stuff ??
13
+
14
+ # mock highline stuff??
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ class TestOauthCli < Test::Unit::TestCase
4
+
5
+ def test_should_init_oauth
6
+ opt = {}
7
+ @client = OauthCli.new(opt)
8
+ assert @client
9
+ end
10
+
11
+ def test_should_add_http_to_host
12
+ opt = { :host => "api.bbc.com", :auth_host => "http://test.domain", :reg_host => "https://test.domain", :consumer_key => "dummy_key"}
13
+ @client = OauthCli.new(opt)
14
+
15
+ assert_equal "http://api.bbc.com", @client.options[:host]
16
+ assert_equal "http://test.domain", @client.options[:auth_host]
17
+ assert_equal "https://test.domain", @client.options[:reg_host]
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ class TestOauthCli < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @oauthc = File.dirname(File.dirname(__FILE__)) + "/bin/oauthc"
7
+ end
8
+
9
+ def test_should_show_help
10
+ output = `#{@oauthc}`
11
+ assert output =~ /Usage: oauthc/
12
+ end
13
+
14
+ def test_should_show_error_on_profile
15
+ output = `#{@oauthc} -p=unknown`
16
+ assert output =~ /Profile unknown not found/
17
+ end
18
+
19
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - rngtng - Tobias Bielohlawek
@@ -34,8 +34,8 @@ cert_chain:
34
34
  I5mOkC+DmQeKRCyukHoWnysL5IyK+l7JEPymkOlNWkl006u5rNu/d7LJJW19+ZvC
35
35
  -----END CERTIFICATE-----
36
36
 
37
- date: 2010-04-20 00:00:00 +02:00
38
- default_executable:
37
+ date: 2010-04-23 00:00:00 +02:00
38
+ default_executable: oauthc
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: highline
@@ -79,6 +79,18 @@ dependencies:
79
79
  version: 0.3.6
80
80
  type: :runtime
81
81
  version_requirements: *id003
82
+ - !ruby/object:Gem::Dependency
83
+ name: mocha
84
+ prerelease: false
85
+ requirement: &id004 !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ type: :development
93
+ version_requirements: *id004
82
94
  description: A simple CLI client to test your oauth API easily
83
95
  email: tobi @nospam@ rngtng.com
84
96
  executables:
@@ -96,9 +108,11 @@ files:
96
108
  - README.rdoc
97
109
  - Rakefile
98
110
  - bin/oauthc
99
- - init.rb
100
111
  - lib/oauth_cli.rb
101
112
  - oauth-cli.gemspec
113
+ - test/helper.rb
114
+ - test/test_oauth_cli.rb
115
+ - test/test_oauthc.rb
102
116
  has_rdoc: true
103
117
  homepage: http://github.com/rngtng/oauth-cli
104
118
  licenses: []
@@ -135,5 +149,6 @@ rubygems_version: 1.3.6
135
149
  signing_key:
136
150
  specification_version: 3
137
151
  summary: A simple CLI client to test your oauth API easily
138
- test_files: []
139
-
152
+ test_files:
153
+ - test/test_oauth_cli.rb
154
+ - test/test_oauthc.rb
metadata.gz.sig CHANGED
Binary file
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'oauth_cli'