oauth-cli 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -72,6 +72,10 @@ oauthc was originally developed to test the {Qype API}[http://www.qype.com/devel
72
72
  ==== What's the difference to the client provided by oauth gem?
73
73
  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
74
74
 
75
+ ==== Are there other clients of similar manner?
76
+ Yes: http://github.com/marcel/twurl
77
+ Very similar but Twitter specific. I whish I'd spot this project earlier ;-)
78
+
75
79
 
76
80
  == Copyright
77
81
  The MIT License
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('oauth-cli', '0.0.4') do |p|
5
+ Echoe.new('oauth-cli', '0.0.5') 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"
data/bin/oauthc CHANGED
@@ -14,7 +14,7 @@ CFG_FILE = ENV['OAUTHC_CONFIG_FILE'] || File.expand_path('~/.oauthconfig')
14
14
 
15
15
  def show_help
16
16
  say <<-help
17
- oauthc version 0.0.4
17
+ oauthc version 0.0.5
18
18
  Usage: oauthc [options] [http_method_verb uri [body]]
19
19
 
20
20
  Options:
@@ -52,36 +52,46 @@ Interactive Commands:
52
52
  help
53
53
  end
54
54
 
55
- if ARGV.empty? || ARGV.any? { |arg| %w( -h --help -help help ).include?(arg) }
55
+ if ARGV.any? { |arg| %w(-h --help -help help).include?(arg) }
56
56
  show_help
57
57
  end
58
58
 
59
59
  #parse CLI input
60
- opt = {}
61
- method, uri, body = ARGV.clone.delete_if do |kv|
62
- next opt[$1.to_sym] = $2 if kv =~ /-?-([^=]+)=(.+)$/
63
- false
64
- end
65
- profile = opt[:profile] || opt[:p] #shortcut for profile
60
+ method, uri, body, opt, profile = OauthCli.parse_args(ARGV)
61
+
62
+ @profiles = YAML.load_file(CFG_FILE) if File.exists?(CFG_FILE)
66
63
 
67
- #load external config if profile given
68
- if profile
69
- unless File.exists?(CFG_FILE)
70
- say " <%= color('# ERROR: Profile File #{CFG_FILE} not found', RED) %>"
71
- show_help
64
+ #find default profile
65
+ if @profiles && (profile.nil? || @profiles[profile].nil?)
66
+ @profiles.each do |key, values|
67
+ profile = key if values['default']
72
68
  end
73
-
74
- cfg_options = YAML.load_file(CFG_FILE)
75
- profile = 'default' if !cfg_options[profile] && cfg_options['default']
76
-
77
- unless cfg_options[profile]
78
- say " <%= color('# ERROR: Profile #{profile} not found', RED) %>"
79
- show_help
69
+ end
70
+
71
+ #give profile selection
72
+ if @profiles && (profile.nil? || @profiles[profile].nil?)
73
+ say " <%= 'Select one of the available profiles" #" or leave empty to create new one' %>"
74
+ @nr_profiles = @profiles.map
75
+ #say " <%= ' 0. - create new one -' %>"
76
+ @nr_profiles.each_with_index do |profile, index|
77
+ say " <%= ' #{index+1}. #{profile.first}' %>"
80
78
  end
79
+ profile = ask ' >> '
80
+ profile = @nr_profiles[profile.to_i-1].first if profile == profile.to_i.to_s && @nr_profiles[profile.to_i-1]
81
+ end
81
82
 
82
- cfg_options[profile].each { |key, value| opt[key.to_sym] = value } #symbolize_keys
83
+ @profiles[profile].each { |key, value| opt[key.to_sym] = value } if @profiles[profile] #symbolize_keys
84
+
85
+ if opt[:host].to_s.empty? || opt[:consumer_key].to_s.empty? || opt[:consumer_secret].to_s.empty?
86
+
83
87
  end
84
88
 
89
+ # unless cfg_options[profile]
90
+ # say " <%= color('# ERROR: Profile #{profile} not found', RED) %>"
91
+ # show_help
92
+ # end
93
+ #
94
+
85
95
  ######## CREATE client
86
96
 
87
97
  @client = OauthCli.new(opt)
@@ -117,6 +127,8 @@ if !ENV['__REPL_WRAPPED'] && system("which rlwrap > /dev/null 2> /dev/null")
117
127
  rlargs = ""
118
128
  #rlargs << " -f #{cfile}" if cfile
119
129
  rlargs << " -H #{hfile}" if hfile
130
+
131
+ ARGV << "-p=#{profile}" if profile
120
132
 
121
133
  exec "rlwrap #{rlargs} #$0 #{ARGV.join(' ')}"
122
134
  end
@@ -127,10 +139,10 @@ loop do
127
139
 
128
140
  begin
129
141
  command, uri, body = $stdin.gets.chomp.split(' ')
130
-
142
+
131
143
  next warn(show_commands) if command =~ /^(help|\?)$/
132
144
  next warn("Use Ctrl-D (i.e. EOF) to exit") if command =~ /^(exit|quit)$/
133
-
145
+
134
146
  @client.request(command, uri, body)
135
147
  next
136
148
  rescue NoMethodError, Interrupt
data/lib/oauth_cli.rb CHANGED
@@ -20,14 +20,14 @@ class OauthCli
20
20
  color = 'YELLOW'
21
21
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
22
22
  say " <%= color('# no consumer_key provided, please create a profile or call the script with:', #{color}) %>"
23
- say " <%= color('# oauthc --consumer_key=<consumer_key> --consumer_secret=<consumer_secret>', #{color}) %>"
23
+ say " <%= color('# oauthc --consumer_key <consumer_key> --consumer_secret <consumer_secret>', #{color}) %>"
24
24
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
25
25
  #please get a key here: #{options[:host]}/api_consumers"
26
26
  return
27
27
  end
28
28
 
29
29
  #add http if missing
30
- [:host, :reg_host, :auth_host].each do |key|
30
+ [:host, :reg_url, :auth_url].each do |key|
31
31
  @options[key] = "http://#{@options[key]}" unless @options[key] =~ /^http/
32
32
  end
33
33
 
@@ -35,13 +35,23 @@ class OauthCli
35
35
  @access_token = OAuth::AccessToken.new(@consumer, @options[:token], @options[:token_secret]) if @options[:token]
36
36
  end
37
37
 
38
+ def self.parse_args(args, opt = {}, last_arg = nil)
39
+ method, uri, body = args.clone.delete_if do |kv|
40
+ next opt[$1.to_sym] = $2 if kv =~ /-?-([^=]+)=(.+)$/ #catches --param=value
41
+ next opt[last_arg] = kv if last_arg && !opt[last_arg] #catches value
42
+ next last_arg = $1.to_sym if kv =~ /^-?-(.+)$/ #catches --param
43
+ false
44
+ end
45
+ [method, uri, body, opt, (opt.delete(:profile) || opt.delete(:p))]
46
+ end
47
+
38
48
  def request(method, uri, body = nil)
39
49
  if method =~ /auth/
40
50
  @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!!
51
+ @options[:auth_url] ||= "#{@options[:host].gsub('api.', 'www.').gsub('v1/', '')}/mobile/authorize" #That's for Qype only!!
42
52
  color = 'YELLOW'
43
53
  say " <%= color('# To authorize, go to ...', #{color}) %>"
44
- say " <%= '# ' + color('#{@options[:auth_host]}#{@request_token.token}', BOLD, UNDERLINE) %>\n"
54
+ say " <%= '# ' + color('#{@options[:auth_url]}?oauth_token=#{@request_token.token}', BOLD, UNDERLINE) %>\n"
45
55
  say " <%= color('# ... and enter given token verifier:', #{color}) %>"
46
56
  verifier = ask " |-- verifier >> "
47
57
 
@@ -55,6 +65,8 @@ class OauthCli
55
65
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
56
66
  say " <%= color('# Authorization SUCCESSFUL', BOLD, #{color}) %>"
57
67
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
68
+ say " <%= color(' token: #{@access_token.token}', #{color}) %>"
69
+ say " <%= color(' token_secret: #{@access_token.secret}', #{color}) %>"
58
70
  rescue
59
71
  color = 'RED'
60
72
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
data/oauth-cli.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{oauth-cli}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
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-23}
10
+ s.date = %q{2010-04-28}
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}
@@ -8,6 +8,16 @@ class TestOauthCli < Test::Unit::TestCase
8
8
  assert @client
9
9
  end
10
10
 
11
+ def test_should_parse_args_with_equal
12
+ args = %w(--profile=test -host=http://host.com get /users?name=test my_body)
13
+ assert_equal ['get', '/users?name=test', 'my_body', {:host => 'http://host.com'}, 'test'], OauthCli.parse_args(args)
14
+ end
15
+
16
+ def test_should_parse_args_without_equal_and_body
17
+ args = %w(-p test --host http://host.com get /users?name=test)
18
+ assert_equal ['get', '/users?name=test', nil, {:host => 'http://host.com'}, 'test'], OauthCli.parse_args(args)
19
+ end
20
+
11
21
  def test_should_add_http_to_host
12
22
  opt = { :host => "api.bbc.com", :auth_host => "http://test.domain", :reg_host => "https://test.domain", :consumer_key => "dummy_key"}
13
23
  @client = OauthCli.new(opt)
data/test/test_oauthc.rb CHANGED
@@ -5,14 +5,14 @@ class TestOauthCli < Test::Unit::TestCase
5
5
  def setup
6
6
  @oauthc = File.dirname(File.dirname(__FILE__)) + "/bin/oauthc"
7
7
  end
8
-
8
+
9
9
  def test_should_show_help
10
- output = `#{@oauthc}`
10
+ output = `#{@oauthc} -h`
11
11
  assert output =~ /Usage: oauthc/
12
12
  end
13
13
 
14
- def test_should_show_error_on_profile
15
- output = `#{@oauthc} -p=unknown`
14
+ def _test_should_show_error_on_profile
15
+ output = `#{@oauthc} -p unknown`
16
16
  assert output =~ /Profile unknown not found/
17
17
  end
18
18
 
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
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - rngtng - Tobias Bielohlawek
@@ -34,7 +34,7 @@ cert_chain:
34
34
  I5mOkC+DmQeKRCyukHoWnysL5IyK+l7JEPymkOlNWkl006u5rNu/d7LJJW19+ZvC
35
35
  -----END CERTIFICATE-----
36
36
 
37
- date: 2010-04-23 00:00:00 +02:00
37
+ date: 2010-04-28 00:00:00 +02:00
38
38
  default_executable: oauthc
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file