oauth-cli 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,7 +1,24 @@
1
1
  // planned: 0.0.X
2
2
  // ---------------------------
3
3
  // on exit, ask if connection data should be saved to profile
4
- // show list of example profiles
4
+
5
+ 0.0.6
6
+ ---------------------------
7
+ updated & cleanedup profile managment
8
+ introduced profile creator to setup new profiles easily
9
+ updated first journey UX: start profile creator if no profile avail and no params given
10
+ added preset auth profiles for Qype, Twitter
11
+ better support for getting authkeys with auto save to current profile
12
+ streamlined output messages and prompts
13
+
14
+
15
+ 0.0.5
16
+ ---------------------------
17
+ show list of example profiles
18
+ equalsign for params is now optional (e.g. 'oauthc -p bbc' now works )
19
+ show auth token and secret after successful auth
20
+ updated config params
21
+
5
22
 
6
23
  0.0.4
7
24
  ---------------------------
@@ -9,6 +26,7 @@ introduced easy auth (by now for Qype API only)
9
26
  added tests
10
27
  "http://" for any host options got optional
11
28
 
29
+
12
30
  0.0.3
13
31
  ---------------------------
14
32
  minor fix to resolve dependencies
data/Manifest CHANGED
@@ -5,6 +5,7 @@ Rakefile
5
5
  bin/oauthc
6
6
  lib/oauth_cli.rb
7
7
  oauth-cli.gemspec
8
+ profiles.yaml
8
9
  test/helper.rb
9
10
  test/test_oauth_cli.rb
10
11
  test/test_oauthc.rb
data/README.rdoc CHANGED
@@ -11,7 +11,7 @@ oauthc [options] [http_method_verb uri [body]]
11
11
 
12
12
  Options:
13
13
  --help Display this message
14
- --profile Name of preset profile to load, put profiles to a .yml file in ~/.oauthconfig
14
+ --profile Name of preset profile to load, put profiles to a yaml file in ~/.oauthconfig
15
15
  --host Host to connect to
16
16
  --consumer_key Consumer Key
17
17
  --consumer_secret Consumer Secret
@@ -54,18 +54,15 @@ oauthc was originally developed to test the {Qype API}[http://www.qype.com/devel
54
54
  == Hints
55
55
  * make sure to have rlwrap installed, to get CLI history support: http://utopia.knoware.nl/~hlub/rlwrap (or "port install rlwarp")
56
56
 
57
-
58
57
  * Bug reports, suggestions, updates: http://github.com/rngtng/oauth-cli/issues
59
58
 
60
59
 
61
60
  == Todos
62
- * save given keys to config, e.g. introduce 'save' command
63
- * go into config mode, if no profiles found and no params specified
64
- * better support for getting authkeys
61
+ * check if host is valid
65
62
  * testing + better docs
66
63
  * check oauth client, streamline!?
67
64
  * add autocomplete for interactive commands
68
- * add auth profiles for Qype, Twitter etc!?
65
+ * profile delete and rename
69
66
 
70
67
  == FAQ
71
68
 
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.5') do |p|
5
+ Echoe.new('oauth-cli', '0.0.6') 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 = ["mocha >=0"]
11
+ p.development_dependencies = ["mocha >=0", "echoe >=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,24 +2,25 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'pp'
5
+
6
+ #workaround to make it work in dev & production mode, any better solutions here??
5
7
  begin
6
- require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/lib/oauth_cli"
8
+ require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/lib/oauth_cli"
7
9
  rescue LoadError
8
10
  require "oauth_cli"
9
11
  end
10
12
 
11
- CFG_FILE = ENV['OAUTHC_CONFIG_FILE'] || File.expand_path('~/.oauthconfig')
12
-
13
- #http://api.betterbecool.com/v1/places/1197081
13
+ PROFILE_CFG_FILE = ENV['OAUTHC_CONFIG_FILE'] || File.expand_path('~/.oauthconfig')
14
+ PROFILE_TMP_FILE = "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/profiles.yaml"
14
15
 
15
16
  def show_help
16
17
  say <<-help
17
- oauthc version 0.0.5
18
+ oauthc version 0.0.6
18
19
  Usage: oauthc [options] [http_method_verb uri [body]]
19
20
 
20
21
  Options:
21
22
  --help Display this message
22
- --profile Name of preset profile to load, put profiles to a .yml file in ~/.oauthconfig
23
+ --profile Name of preset profile to load, put profiles to a yaml file in ~/.oauthconfig
23
24
  --host Host to connect to
24
25
  --consumer_key Consumer Key
25
26
  --consumer_secret Consumer Secret
@@ -56,46 +57,59 @@ if ARGV.any? { |arg| %w(-h --help -help help).include?(arg) }
56
57
  show_help
57
58
  end
58
59
 
59
- #parse CLI input
60
- method, uri, body, opt, profile = OauthCli.parse_args(ARGV)
61
-
62
- @profiles = YAML.load_file(CFG_FILE) if File.exists?(CFG_FILE)
63
-
64
- #find default profile
65
- if @profiles && (profile.nil? || @profiles[profile].nil?)
66
- @profiles.each do |key, values|
67
- profile = key if values['default']
68
- end
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}' %>"
60
+ ### Read profiles
61
+ OauthCli.load_profiles(PROFILE_CFG_FILE, PROFILE_TMP_FILE)
62
+
63
+ ### parse CLI input
64
+ method, uri, body, profile = OauthCli.parse_args(ARGV)
65
+
66
+ ### Create client
67
+ @client = OauthCli.new(profile)
68
+
69
+ if !@client.connected?
70
+ say_message("Welcome to Oauth Commandline Client.", 'YELLOW')
71
+
72
+ #give profile selection
73
+ if OauthCli.profiles.keys.any?
74
+ profile = choose do |menu|
75
+ menu.header = "Choose profile to load"
76
+ menu.prompt = ">> "
77
+ menu.choices(*(OauthCli.profiles.keys << 'create new') )
78
+ end
79
+ @client.connect(profile) unless profile == 'create new'
78
80
  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
82
-
83
- @profiles[profile].each { |key, value| opt[key.to_sym] = value } if @profiles[profile] #symbolize_keys
84
81
 
85
- if opt[:host].to_s.empty? || opt[:consumer_key].to_s.empty? || opt[:consumer_secret].to_s.empty?
82
+ while !@client.connected?
83
+ say("No profiles setups were found, please create one first.") if OauthCli.profiles.empty?
84
+
85
+ profile = template = choose do |menu|
86
+ menu.header = "Choose profile template"
87
+ menu.prompt = ">> "
88
+ menu.choices(*(OauthCli.templates.keys << 'custom') )
89
+ end
90
+
91
+ say_message "Creating #{template} profile", 'YELLOW'
92
+
93
+ say "Profile '#{profile}' already exists, please choose another name." if OauthCli.profiles[profile]
94
+ profile = ask_prompt "Profile name" if !OauthCli.templates[profile] || OauthCli.profiles[profile]
95
+
96
+ OauthCli.add_profile(profile, OauthCli.templates[template] || {})
97
+
98
+ say "\n <%= 'Go to ' + color('#{OauthCli.profiles[profile][:reg_url]}', BOLD, UNDERLINE) + ' to register and retrieve your oauth consumer key and secret' %>\n\n" if OauthCli.profiles[profile][:reg_url]
99
+
100
+ OauthCli.profiles[profile][:host] ||= ask_prompt "Oauth Host"
101
+ OauthCli.profiles[profile][:auth_url] ||= ask_prompt "Authorization Url"
102
+ OauthCli.profiles[profile][:consumer_key] = ask_prompt "Consumer Key"
103
+ OauthCli.profiles[profile][:consumer_secret] = ask_prompt "Consumer Secret"
104
+
105
+ @client.connect(profile)
106
+ OauthCli.save_profiles
86
107
 
108
+ say_message "Profile Setup SUCCESSFUL - saved as: #{profile}", 'GREEN'
109
+ say "Type 'auth' ot authorize profile, type 'help' for more"
110
+ end
87
111
  end
88
112
 
89
- # unless cfg_options[profile]
90
- # say " <%= color('# ERROR: Profile #{profile} not found', RED) %>"
91
- # show_help
92
- # end
93
- #
94
-
95
- ######## CREATE client
96
-
97
- @client = OauthCli.new(opt)
98
-
99
113
  if method && uri
100
114
  @client.request(method, uri, body)
101
115
  exit
@@ -103,7 +117,7 @@ end
103
117
 
104
118
  ######## START Interactive mode
105
119
 
106
- ## following lines are shameless stolen from repl -> http://http://github.com/defunkt/repl
120
+ ## following lines are shamelessly stolen from repl -> http://http://github.com/defunkt/repl
107
121
  # completion_dir = ENV['REPL_COMPLETION_DIR'] || "~/.repl"
108
122
  # if File.exists?(cdir = File.expand_path(completion_dir))
109
123
  # script = ARGV.detect { |a| a !~ /^-/ }
@@ -133,17 +147,38 @@ if !ENV['__REPL_WRAPPED'] && system("which rlwrap > /dev/null 2> /dev/null")
133
147
  exec "rlwrap #{rlargs} #$0 #{ARGV.join(' ')}"
134
148
  end
135
149
 
150
+ prompt = ENV['REPL_PROMPT'] || "#{profile} >>"
136
151
 
137
152
  loop do
138
- print ENV['REPL_PROMPT'] || "#{opt[:name] || profile} >> "
139
-
140
153
  begin
141
- command, uri, body = $stdin.gets.chomp.split(' ')
154
+ input = ask "<%= color('#{prompt}', BOLD) %> "
155
+ command, uri, body = input.chomp.split(' ')
142
156
 
143
157
  next warn(show_commands) if command =~ /^(help|\?)$/
144
158
  next warn("Use Ctrl-D (i.e. EOF) to exit") if command =~ /^(exit|quit)$/
145
159
 
146
- @client.request(command, uri, body)
160
+ if command =~ /auth/
161
+ say_message "Starting Authorization", 'YELLOW'
162
+ say "\n"
163
+ say " <%= 'Go to ' + color('#{@client.access_request_url}', BOLD, UNDERLINE) + ' to retrieve token verifier' %>\n\n"
164
+ verifier = ask_prompt "verifier"
165
+
166
+ begin
167
+ @access_token = @client.access_token(verifier)
168
+ OauthCli.profiles[profile][:token] = @access_token.token
169
+ OauthCli.profiles[profile][:secret] = @access_token.secret
170
+ OauthCli.save_profiles
171
+
172
+ say_message "Authorization SUCCESSFUL and saved to profile: #{profile}", 'GREEN'
173
+ say " token: #{@access_token.token}"
174
+ say " secret: #{@access_token.secret}"
175
+ rescue => message
176
+ say_message "Authorization FAILED: #{message}", 'RED'
177
+ end
178
+ else
179
+ @client.request(command, uri, body)
180
+ end
181
+
147
182
  next
148
183
  rescue NoMethodError, Interrupt
149
184
  #save_config unless profile
data/lib/oauth_cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'highline/import'
2
2
  require 'oauth'
3
3
  require 'json'
4
+ require 'yaml'
4
5
 
5
6
  begin
6
7
  require 'ap' #try to load awesome_print for nice json output
@@ -13,18 +14,14 @@ class OauthCli
13
14
 
14
15
  attr_reader :options
15
16
 
16
- def initialize(options = {})
17
- @options = options
18
-
19
- if options[:consumer_key].to_s.empty?
20
- color = 'YELLOW'
21
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
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}) %>"
24
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
25
- #please get a key here: #{options[:host]}/api_consumers"
26
- return
27
- end
17
+ def initialize(profile = nil)
18
+ @options = {}
19
+ connect(profile)
20
+ end
21
+
22
+ def connect(profile)
23
+ return false if !profile.is_a?(Hash) && !OauthCli.profiles[profile]
24
+ @options = OauthCli.profiles[profile] || profile
28
25
 
29
26
  #add http if missing
30
27
  [:host, :reg_url, :auth_url].each do |key|
@@ -33,59 +30,38 @@ class OauthCli
33
30
 
34
31
  @consumer = OAuth::Consumer.new(@options[:consumer_key], @options[:consumer_secret], :site => @options[:host])
35
32
  @access_token = OAuth::AccessToken.new(@consumer, @options[:token], @options[:token_secret]) if @options[:token]
33
+
34
+ connected?
36
35
  end
37
36
 
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))]
37
+ def connected?
38
+ # TODO check if host available?
39
+ @options[:consumer_key] && @options[:consumer_secret] && @options[:host]
40
+ end
41
+
42
+ def auth?
43
+ @access_token
46
44
  end
47
45
 
46
+ def access_request_url
47
+ @request_token = @consumer.get_request_token({}, "oauth_callback" => "oob")
48
+ @options[:auth_url] ||= "#{@options[:host].gsub('api.', 'www.').gsub('v1/', '')}/mobile/authorize" #That's for Qype only!!
49
+ url = "#{@options[:auth_url]}?oauth_token=#{@request_token.token}"
50
+ end
51
+
52
+ def access_token(verifier)
53
+ request_url unless @request_token
54
+ @access_token = @request_token.get_access_token({}, "oauth_verifier" => verifier)
55
+ end
56
+
48
57
  def request(method, uri, body = nil)
49
- if method =~ /auth/
50
- @request_token = @consumer.get_request_token({}, "oauth_callback" => "oob")
51
- @options[:auth_url] ||= "#{@options[:host].gsub('api.', 'www.').gsub('v1/', '')}/mobile/authorize" #That's for Qype only!!
52
- color = 'YELLOW'
53
- say " <%= color('# To authorize, go to ...', #{color}) %>"
54
- say " <%= '# ' + color('#{@options[:auth_url]}?oauth_token=#{@request_token.token}', BOLD, UNDERLINE) %>\n"
55
- say " <%= color('# ... and enter given token verifier:', #{color}) %>"
56
- verifier = ask " |-- verifier >> "
57
-
58
- begin
59
- @access_token = @request_token.get_access_token({}, "oauth_verifier" => verifier)
60
-
61
- @options[:token] = @access_token.token
62
- @options[:token_secret] = @access_token.secret
63
-
64
- color = 'GREEN'
65
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
66
- say " <%= color('# Authorization SUCCESSFUL', BOLD, #{color}) %>"
67
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
68
- say " <%= color(' token: #{@access_token.token}', #{color}) %>"
69
- say " <%= color(' token_secret: #{@access_token.secret}', #{color}) %>"
70
- rescue
71
- color = 'RED'
72
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
73
- say " <%= color('# Authorization FAILED', BOLD, #{color}) %>"
74
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
75
- end
76
- return
77
- end
78
-
79
58
  unless %w(get post put delete).include? method.to_s
80
- color = 'RED'
81
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
82
- say " <%= color('# Wrong HTTP Method: #{method} - calling #{@options[:host]}#{uri}', BOLD, #{color}) %>"
83
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
59
+ say_message "Wrong HTTP Method: #{method} - calling #{@options[:host]}#{uri}", 'RED'
84
60
  return
85
61
  end
86
62
 
87
- uri = ask " |-- request uri >> " if !uri
88
- body = ask " |-- request body >> " if !body && (method == "post" || method == "put")
63
+ uri = ask_prompt "request uri" if !uri
64
+ body = ask_prompt "request body" if !body && (method == "post" || method == "put")
89
65
 
90
66
  url = @options[:host] + uri
91
67
 
@@ -97,9 +73,7 @@ class OauthCli
97
73
  header = response.header
98
74
 
99
75
  color = (response.code.to_i < 400) ? 'GREEN' : 'RED'
100
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
101
- say " <%= color('# Status: #{header.code} #{header.message} - calling #{@options[:host]}#{uri}', BOLD, #{color}) %>"
102
- say " <%= color('# -------------------------------------------------------------------------', #{color}) %>"
76
+ say_message "Status: #{header.code} #{header.message} - calling #{@options[:host]}#{uri}", color
103
77
 
104
78
  body = response.body
105
79
  if header.content_type =~ /json/
@@ -112,4 +86,96 @@ class OauthCli
112
86
  say body
113
87
  end
114
88
 
115
- end
89
+ ####### Static Setup Mehtods
90
+
91
+ def self.inialize
92
+ @profiles || {}
93
+ end
94
+
95
+ def self.load_profiles(cfg_file, tmp_file)
96
+ @cfg_file = cfg_file #keep so we can save back to file
97
+ @profiles = load(cfg_file)
98
+ @templates = load(tmp_file)
99
+ end
100
+
101
+ def self.save_profiles
102
+ return unless @cfg_file
103
+ File.open(@cfg_file, 'w') do |out|
104
+ YAML.dump(@profiles, out)
105
+ end
106
+ end
107
+
108
+ def self.add_profile(name, values)
109
+ @profiles[name] = values
110
+ name
111
+ end
112
+
113
+ def self.profiles
114
+ @profiles || {}
115
+ end
116
+
117
+ def self.templates
118
+ @templates || {}
119
+ end
120
+
121
+ def self.parse_args(args, opt = {}, last_arg = nil)
122
+ @profiles ||= {}
123
+ method, uri, body = args.clone.delete_if do |kv|
124
+ next opt[$1.to_sym] = $2 if kv =~ /-?-([^=]+)=(.+)$/ #catches --param=value
125
+ next opt[last_arg] = kv if last_arg && !opt[last_arg] #catches value
126
+ next last_arg = $1.to_sym if kv =~ /^-?-(.+)$/ #catches --param
127
+ false
128
+ end
129
+
130
+ profile = opt.delete(:profile) || opt.delete(:p)
131
+
132
+ if !@profiles[profile] && opt.any?
133
+ profile ||= 'commandline'
134
+ @profiles[profile] = opt
135
+ save_profiles unless profile == 'commandline'
136
+ end
137
+
138
+ if !@profiles[profile] && @default_profile
139
+ profile = @default_profile
140
+ say "Using default profile: #{profile}"
141
+ end
142
+
143
+ if profile && !@profiles[profile]
144
+ say_error "Profile #{profile} not found"
145
+ profile = nil
146
+ end
147
+
148
+ [method, uri, body, profile]
149
+ end
150
+
151
+ private
152
+ def self.load(file)
153
+ hash = YAML.load_file(file) if File.exists?(file)
154
+ return {} unless hash.is_a?(Hash)
155
+
156
+ #symbolises keys and finde default profile
157
+ hash.each do |profile, options|
158
+ options.keys.each do |key|
159
+ hash[profile][key.to_sym] = hash[profile].delete(key)
160
+ @default_profile = profile if key.to_sym == :default
161
+ end
162
+ end
163
+ hash
164
+ end
165
+
166
+ end
167
+
168
+
169
+ def say_message(message, color = 'WHITE')
170
+ say "<%= color('# -------------------------------------------------------------------------', #{color}) %>"
171
+ say "<%= color('# #{message}', BOLD, #{color} ) %>"
172
+ say "<%= color('# -------------------------------------------------------------------------', #{color}) %>"
173
+ end
174
+
175
+ def say_error(error)
176
+ say_message "ERROR: #{error}", 'RED'
177
+ end
178
+
179
+ def ask_prompt(question)
180
+ ask " |-- #{question} >> "
181
+ 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.5"
5
+ s.version = "0.0.6"
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-28}
9
+ s.cert_chain = ["/Users/ted/.ssh/gem-public_cert.pem"]
10
+ s.date = %q{2010-06-09}
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", "lib/oauth_cli.rb", "oauth-cli.gemspec", "test/helper.rb", "test/test_oauth_cli.rb", "test/test_oauthc.rb"]
16
+ s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "bin/oauthc", "lib/oauth_cli.rb", "oauth-cli.gemspec", "profiles.yaml", "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"]
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
  s.test_files = ["test/test_oauth_cli.rb", "test/test_oauthc.rb"]
25
25
 
@@ -32,16 +32,19 @@ Gem::Specification.new do |s|
32
32
  s.add_runtime_dependency(%q<json>, [">= 1.1.9"])
33
33
  s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
34
34
  s.add_development_dependency(%q<mocha>, [">= 0"])
35
+ s.add_development_dependency(%q<echoe>, [">= 0"])
35
36
  else
36
37
  s.add_dependency(%q<highline>, [">= 1.5.1"])
37
38
  s.add_dependency(%q<json>, [">= 1.1.9"])
38
39
  s.add_dependency(%q<oauth>, [">= 0.3.6"])
39
40
  s.add_dependency(%q<mocha>, [">= 0"])
41
+ s.add_dependency(%q<echoe>, [">= 0"])
40
42
  end
41
43
  else
42
44
  s.add_dependency(%q<highline>, [">= 1.5.1"])
43
45
  s.add_dependency(%q<json>, [">= 1.1.9"])
44
46
  s.add_dependency(%q<oauth>, [">= 0.3.6"])
45
47
  s.add_dependency(%q<mocha>, [">= 0"])
48
+ s.add_dependency(%q<echoe>, [">= 0"])
46
49
  end
47
50
  end
data/profiles.yaml ADDED
@@ -0,0 +1,9 @@
1
+ twitter:
2
+ :host: https://twitter.com/
3
+ :reg_url: twitter.com/oauth_clients
4
+ :auth_url: twitter.com/oauth/authorize
5
+
6
+ qype:
7
+ :host: api.qype.com/v1
8
+ :reg_url: www.qype.com/api_consumers
9
+ :auth_url: www.qype.com/mobile/authorize
@@ -3,27 +3,38 @@ require 'helper'
3
3
  class TestOauthCli < Test::Unit::TestCase
4
4
 
5
5
  def test_should_init_oauth
6
- opt = {}
7
- @client = OauthCli.new(opt)
8
- assert @client
6
+ assert OauthCli.new
9
7
  end
10
8
 
11
9
  def test_should_parse_args_with_equal
12
10
  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)
11
+ assert_equal ['get', '/users?name=test', 'my_body', 'test'], OauthCli.parse_args(args)
12
+ end
13
+
14
+ def test_should_parse_args_with_equal_no_profile
15
+ args = %w(-host=http://host.com get /users?name=test my_body)
16
+ assert_equal ['get', '/users?name=test', 'my_body', 'commandline'], OauthCli.parse_args(args)
14
17
  end
15
18
 
16
19
  def test_should_parse_args_without_equal_and_body
17
20
  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)
21
+ assert_equal ['get', '/users?name=test', nil, 'test'], OauthCli.parse_args(args)
19
22
  end
20
23
 
21
- def test_should_add_http_to_host
22
- opt = { :host => "api.bbc.com", :auth_host => "http://test.domain", :reg_host => "https://test.domain", :consumer_key => "dummy_key"}
24
+ def test_should_not_be_connected_on_empty_args
25
+ assert !OauthCli.new.connected?
26
+ end
27
+
28
+ def test_should_be_connected
29
+ assert OauthCli.new( :consumer_key => 'key', :consumer_secret => 'secret', :host => 'host' ).connected?
30
+ end
31
+
32
+ def test_should_add_http_to_url
33
+ opt = { :host => "api.bbc.com", :auth_url => "http://test.domain", :reg_url => "https://test.domain", :consumer_key => "dummy_key"}
23
34
  @client = OauthCli.new(opt)
24
35
 
25
36
  assert_equal "http://api.bbc.com", @client.options[:host]
26
- assert_equal "http://test.domain", @client.options[:auth_host]
27
- assert_equal "https://test.domain", @client.options[:reg_host]
37
+ assert_equal "http://test.domain", @client.options[:auth_url]
38
+ assert_equal "https://test.domain", @client.options[:reg_url]
28
39
  end
29
40
  end
data/test/test_oauthc.rb CHANGED
@@ -12,7 +12,12 @@ class TestOauthCli < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def _test_should_show_error_on_profile
15
- output = `#{@oauthc} -p unknown`
15
+ require 'highline/import'
16
+ HighLine.any_instance.stubs(:choose).returns("")
17
+
18
+ OauthCli.stubs(:parse_args).returns(['get', '/asd', '', 'unknown', {}])
19
+ OauthCli.any_instance.stubs(:request).returns("")
20
+ load "../bin/oauthc"
16
21
  assert output =~ /Profile unknown not found/
17
22
  end
18
23
 
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
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
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-28 00:00:00 +02:00
37
+ date: 2010-06-09 00:00:00 +02:00
38
38
  default_executable: oauthc
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
@@ -91,6 +91,18 @@ dependencies:
91
91
  version: "0"
92
92
  type: :development
93
93
  version_requirements: *id004
94
+ - !ruby/object:Gem::Dependency
95
+ name: echoe
96
+ prerelease: false
97
+ requirement: &id005 !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :development
105
+ version_requirements: *id005
94
106
  description: A simple CLI client to test your oauth API easily
95
107
  email: tobi @nospam@ rngtng.com
96
108
  executables:
@@ -110,6 +122,7 @@ files:
110
122
  - bin/oauthc
111
123
  - lib/oauth_cli.rb
112
124
  - oauth-cli.gemspec
125
+ - profiles.yaml
113
126
  - test/helper.rb
114
127
  - test/test_oauth_cli.rb
115
128
  - test/test_oauthc.rb
metadata.gz.sig CHANGED
Binary file