oauth-cli 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ // 0.0.3
2
+ // ---------------------------
3
+ // on exit, ask if connection data should be saved to profile
4
+ // show list of example profiles
5
+
6
+ 0.0.2
7
+ ---------------------------
8
+ got rid of repl dependency
9
+ added default profile, use $OAUTHC_CONFIG_FILE to customize default config file path
10
+ show profile name in prompt
11
+ updated help for CLI and interactive mode
12
+ ask for URI if not given
13
+ show error if wrong http method verb
14
+ inline authorization process, triggered by 'auth' command
15
+ added option to set default content_type/mime_type
16
+ nice json syntax highlight with awesome_print
17
+ set default content & mime type
18
+
1
19
 
2
20
  0.0.1
3
21
  ---------------------------
data/Manifest CHANGED
@@ -1,7 +1,7 @@
1
- CHANGELOG
2
- Manifest
3
- README.rdoc
4
- Rakefile
5
1
  bin/oauthc
2
+ CHANGELOG
6
3
  init.rb
7
4
  lib/oauth_cli.rb
5
+ Manifest
6
+ Rakefile
7
+ README.rdoc
data/README.rdoc CHANGED
@@ -7,12 +7,36 @@ oauth-cli is packed as gem, install with:
7
7
 
8
8
 
9
9
  == Usage
10
- [repl] oauthc [options] <method> <uri> [<body>]
10
+ oauthc [options] [http_method_verb uri [body]]
11
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
12
+ Options:
13
+ --help Display this message
14
+ --profile Name of preset profile to load, put profiles to a .yml file in ~/.oauthconfig
15
+ --host Host to connect to
16
+ --consumer_key Consumer Key
17
+ --consumer_secret Consumer Secret
18
+ --token Authentication Token
19
+ --token_secret Authentication Secret
20
+ --mime_type Set mime type, default: application/xml
21
+ --content_type Set content type, default: application/xml
22
+
23
+ Request params (leave blank for interactive mode)
24
+ http_method_verb nay method of get, post, put or delete
25
+ uri Uri to request
26
+ body Body attached to request
27
+
28
+
29
+ === Interactive Mode
30
+ if no request params are specified, interactive mode is started. Those commands are available:
31
+
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
37
+
38
+ auth Request authentication token
39
+ help Display this message
16
40
 
17
41
 
18
42
  == Examples
@@ -28,13 +52,19 @@ oauthc was originally developed to test the {Qype API}[http://www.qype.com/devel
28
52
 
29
53
 
30
54
  == Hints
31
- * use with repl gem for nice handling, see http://github.com/defunkt/repl
55
+ * use with repl gem for nice handling, see: http://github.com/defunkt/repl
32
56
  * make sure to have rlwrap installed, too: http://utopia.knoware.nl/~hlub/rlwrap1
57
+ * Bug reports, suggestions, updates: http://github.com/rngtng/oauth-cli/issues
33
58
 
34
59
 
35
60
  == Todos
36
- * save given keys to config
37
-
61
+ * save given keys to config, e-g introduce 'save' command
62
+ * go into config mode, if no profiles found and no params specified
63
+ * better support for getting authkeys
64
+ * testing + better docs
65
+ * check oauth client, streamline!?
66
+ * add autocomplete
67
+ * add auth profiles for Qype, Twitter etc!?
38
68
 
39
69
  == FAQ
40
70
 
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.1') do |p|
5
+ Echoe.new('oauth-cli', '0.0.2') 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
11
  p.development_dependencies = []
12
- p.runtime_dependencies = ["highline >=1.5.1", "json >=1.1.9", "oauth >=0.3.6", "repl >=0.2.1"]
12
+ p.runtime_dependencies = ["highline >=1.5.1", "json >=1.1.9", "oauth >=0.3.6"]
13
13
  end
data/bin/oauthc CHANGED
@@ -1,6 +1,138 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require 'oauth_cli'
4
+ require 'pp'
5
+ require 'lib/oauth_cli'
6
+
7
+ CFG_FILE = ENV['OAUTHC_CONFIG_FILE'] || File.expand_path('~/.oauthconfig')
8
+
9
+ def show_help
10
+ say <<-help
11
+ oauthc version 0.0.2
12
+ Usage: oauthc [options] [http_method_verb uri [body]]
13
+
14
+ Options:
15
+ --help Display this message
16
+ --profile Name of preset profile to load, put profiles to a .yml file in ~/.oauthconfig
17
+ --host Host to connect to
18
+ --consumer_key Consumer Key
19
+ --consumer_secret Consumer Secret
20
+ --token Authentication Token
21
+ --token_secret Authentication Secret
22
+ --mime_type Set mime type, default: application/xml
23
+ --content_type Set content type, default: application/xml
24
+
25
+ Request params (leave blank for interactive mode)
26
+ http_method_verb any method of get, post, put or delete
27
+ uri Uri to request
28
+ body Body attached to request
29
+
30
+ Bug reports, suggestions, updates:
31
+ http://github.com/rngtng/oauth-cli/issues
32
+ help
33
+ exit
34
+ end
35
+
36
+ def show_commands
37
+ say <<-help
38
+ Interactive Commands:
39
+ get uri Get request for given uri
40
+ post uri [body] Post request for given uri, asks for body if not provided
41
+ put uri [body] Put request for given uri, asks for body if not provided
42
+ delete uri Delete request for given uri
43
+
44
+ auth Request authentication token
45
+ help Display this message
46
+ help
47
+ end
48
+
49
+ if ARGV.empty? || ARGV.any? { |arg| %w( -h --help -help help ).include?(arg) }
50
+ show_help
51
+ end
52
+
53
+ #parse CLI input
54
+ opt = {}
55
+ method, uri, body = ARGV.clone.delete_if do |kv|
56
+ next opt[$1.to_sym] = $2 if kv =~ /-?-([^=]+)=(.+)$/
57
+ false
58
+ end
59
+ profile = opt[:profile] || opt[:p] #shortcut for profile
60
+
61
+ #load external config if profile given
62
+ if profile
63
+ unless File.exists?(CFG_FILE)
64
+ say " <%= color('# ERROR: Profile File #{CFG_FILE} not found', RED) %>"
65
+ show_help
66
+ end
67
+
68
+ cfg_options = YAML.load_file(CFG_FILE)
69
+ profile = 'default' if !cfg_options[profile] && cfg_options['default']
70
+
71
+ unless cfg_options[profile]
72
+ say " <%= color('# ERROR: Profile #{profile} not found', RED) %>"
73
+ show_help
74
+ end
75
+
76
+ cfg_options[profile].each { |key, value| opt[key.to_sym] = value } #symbolize_keys
77
+ end
78
+
79
+ ######## CREATE client
80
+
81
+ @client = OauthCli.new(opt)
82
+
83
+ if method && uri
84
+ @client.request(method, uri, body)
85
+ exit
86
+ end
87
+
88
+ ######## START Interactive mode
89
+
90
+ ## following lines are shameless stolen from repl -> http://http://github.com/defunkt/repl
91
+ # completion_dir = ENV['REPL_COMPLETION_DIR'] || "~/.repl"
92
+ # if File.exists?(cdir = File.expand_path(completion_dir))
93
+ # script = ARGV.detect { |a| a !~ /^-/ }
94
+ # if script
95
+ # cfile = Dir[cdir + '/' + File.basename(script)].first
96
+ # cfile = nil if cfile && !File.exists?(cfile)
97
+ # end
98
+ # end
99
+
100
+ history_dir = ENV['OAUTHC_HISTORY_DIR'] || "~/"
101
+ if File.exists?(hdir = File.expand_path(history_dir))
102
+ if script = ARGV.detect { |a| a !~ /^-/ }
103
+ script = File.basename(script)
104
+ hfile = "#{hdir}/.#{oauthc}_history" #TODO include profile name???
105
+ end
106
+ end
107
+
108
+ if !ENV['__REPL_WRAPPED'] && system("which rlwrap > /dev/null 2> /dev/null")
109
+ ENV['__REPL_WRAPPED'] = '0'
110
+
111
+ rlargs = ""
112
+ #rlargs << " -f #{cfile}" if cfile
113
+ rlargs << " -H #{hfile}" if hfile
114
+
115
+ exec "rlwrap #{rlargs} #$0 #{ARGV.join(' ')}"
116
+ end
117
+
118
+
119
+ loop do
120
+ print ENV['REPL_PROMPT'] || "#{opt[:name] || profile} >> "
121
+
122
+ begin
123
+ command, uri, body = $stdin.gets.chomp.split(' ')
124
+
125
+ next warn(show_commands) if command =~ /^(help|\?)$/
126
+ next warn("Use Ctrl-D (i.e. EOF) to exit") if command =~ /^(exit|quit)$/
127
+
128
+ @client.request(command, uri, body)
129
+ next
130
+ rescue NoMethodError, Interrupt
131
+ #save_config unless profile
132
+ puts
133
+ exit
134
+ rescue
135
+ end
136
+
137
+ end
5
138
 
6
- OauthCli.main($*)
data/lib/oauth_cli.rb CHANGED
@@ -2,89 +2,83 @@ require 'highline/import'
2
2
  require 'oauth'
3
3
  require 'json'
4
4
 
5
- CFG_FILE = File.expand_path('~/.oauthconfig')
5
+ begin
6
+ require 'ap'
7
+ rescue LoadError
8
+ end
9
+
6
10
  HighLine.track_eof = false #hotfix to make highline work
7
11
 
8
12
  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
13
 
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)
14
+ def initialize( options = {})
15
+ @options = options
16
+
49
17
  if options[:consumer_key].to_s.empty?
50
- color = 'YELLOW'
18
+ color = 'YELLOW'
51
19
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
52
- say " <%= color('# no consumer_key provided, call the script with:', #{color}) %>"
20
+ say " <%= color('# no consumer_key provided, please create a profile or call the script with:', #{color}) %>"
53
21
  say " <%= color('# oauthc --consumer_key=<consumer_key> --consumer_secret=<consumer_secret>', #{color}) %>"
54
22
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
55
23
  #please get a key here: http://#{options[:host]}/api_consumers"
56
24
  exit
57
25
  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
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]
29
+ end
30
+
31
+ def request(method, uri, body = nil)
32
+ if method =~ /auth/
66
33
  @request_token = @consumer.get_request_token({}, "oauth_callback" => "oob")
67
- color = 'YELLOW'
34
+ color = 'YELLOW'
68
35
  say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
69
- say " <%= color('# no access token found please provide verifier to for tokens:', #{color}) %>"
70
- verifier = ask ">>"
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)
71
40
 
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
41
+ options[:token] = @access_token.token
42
+ options[:token_secret] = @access_token.secret
43
+
44
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
45
+ end
46
+
47
+ unless %w(get post put delete).include? method.to_s
48
+ color = 'RED'
49
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
50
+ say " <%= color('# Wrong HTTP Method: #{method} - calling #{@options[:host]}#{uri}', BOLD, #{color}) %>"
51
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
52
+ return
53
+ end
54
+
55
+ uri = ask " |-- request uri >> " if !uri
56
+ body = ask " |-- request body >> " if !body && (method == "post" || method == "put")
57
+
58
+ url = "http://#{@options[:host]}#{uri}"
59
+
60
+ @options[:mime_type] ||= (url =~ /\.json/) ? "application/json" : "application/xml"
61
+ @options[:content_type] ||= (url =~ /\.json/) ? "application/json" : "application/xml"
62
+
63
+ response = @consumer.request(method, url, @access_token, {}, body, { 'Accept' => @options[:mime_type], 'Content-Type' => @options[:content_type] })
64
+
65
+ header = response.header
66
+
67
+ color = (response.code.to_i < 400) ? 'GREEN' : 'RED'
68
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
69
+ say " <%= color('# Status: #{header.code} #{header.message} - calling #{@options[:host]}#{uri}', BOLD, #{color}) %>"
70
+ say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
71
+
72
+ body = response.body
73
+ if header.content_type =~ /.json/
74
+ body = JSON.parse(body)
75
+ ap(body) rescue say(JSON.pretty_generate(body))
76
+ return
77
77
  end
78
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
79
+ body = " <%= color('# #{$1.gsub("'", "")} ', RED) %>" if body =~ /<pre>(.+)<\/pre>/
80
+ say body
89
81
  end
82
+
83
+
90
84
  end
data/oauth-cli.gemspec CHANGED
@@ -2,24 +2,24 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{oauth-cli}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
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
- s.cert_chain = ["/Users/tobiasb/.ssh/gem-public_cert.pem"]
10
- s.date = %q{2010-04-09}
9
+ s.cert_chain = ["/Users/ted/.ssh/gem-public_cert.pem"]
10
+ s.date = %q{2010-04-14}
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
- 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"]
15
+ s.extra_rdoc_files = ["bin/oauthc", "CHANGELOG", "lib/oauth_cli.rb", "README.rdoc"]
16
+ s.files = ["bin/oauthc", "CHANGELOG", "init.rb", "lib/oauth_cli.rb", "Manifest", "Rakefile", "README.rdoc", "oauth-cli.gemspec"]
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"]
20
20
  s.rubyforge_project = %q{oauth-cli}
21
21
  s.rubygems_version = %q{1.3.6}
22
- s.signing_key = %q{/Users/tobiasb/.ssh/gem-private_key.pem}
22
+ s.signing_key = %q{/Users/ted/.ssh/gem-private_key.pem}
23
23
  s.summary = %q{A simple CLI client to test your oauth API easily}
24
24
 
25
25
  if s.respond_to? :specification_version then
@@ -30,17 +30,14 @@ Gem::Specification.new do |s|
30
30
  s.add_runtime_dependency(%q<highline>, [">= 1.5.1"])
31
31
  s.add_runtime_dependency(%q<json>, [">= 1.1.9"])
32
32
  s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
33
- s.add_runtime_dependency(%q<repl>, [">= 0.2.1"])
34
33
  else
35
34
  s.add_dependency(%q<highline>, [">= 1.5.1"])
36
35
  s.add_dependency(%q<json>, [">= 1.1.9"])
37
36
  s.add_dependency(%q<oauth>, [">= 0.3.6"])
38
- s.add_dependency(%q<repl>, [">= 0.2.1"])
39
37
  end
40
38
  else
41
39
  s.add_dependency(%q<highline>, [">= 1.5.1"])
42
40
  s.add_dependency(%q<json>, [">= 1.1.9"])
43
41
  s.add_dependency(%q<oauth>, [">= 0.3.6"])
44
- s.add_dependency(%q<repl>, [">= 0.2.1"])
45
42
  end
46
43
  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
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
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-09 00:00:00 +02:00
37
+ date: 2010-04-14 00:00:00 +02:00
38
38
  default_executable: oauthc
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
@@ -79,20 +79,6 @@ dependencies:
79
79
  version: 0.3.6
80
80
  type: :runtime
81
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
82
  description: A simple CLI client to test your oauth API easily
97
83
  email: tobi @nospam@ rngtng.com
98
84
  executables:
@@ -100,18 +86,18 @@ executables:
100
86
  extensions: []
101
87
 
102
88
  extra_rdoc_files:
103
- - CHANGELOG
104
- - README.rdoc
105
89
  - bin/oauthc
106
- - lib/oauth_cli.rb
107
- files:
108
90
  - CHANGELOG
109
- - Manifest
91
+ - lib/oauth_cli.rb
110
92
  - README.rdoc
111
- - Rakefile
93
+ files:
112
94
  - bin/oauthc
95
+ - CHANGELOG
113
96
  - init.rb
114
97
  - lib/oauth_cli.rb
98
+ - Manifest
99
+ - Rakefile
100
+ - README.rdoc
115
101
  - oauth-cli.gemspec
116
102
  has_rdoc: true
117
103
  homepage: http://github.com/rngtng/oauth-cli
metadata.gz.sig CHANGED
Binary file