oa_test 0.0.1

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/bin/oa_test ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ #require File.expand_path(
3
+ # File.join(File.dirname(__FILE__),%w[.. lib oa_test]))
4
+ #wpath= File.dirname(__FILE__).gsub(/bin$/,'')
5
+
6
+ def howto_oa_test
7
+ puts <<END
8
+
9
+ How to oa_test:
10
+ ~~~~~~~~~~~~~~~~~~~~~~~
11
+ syntax:
12
+ oa_test [--consumer:token/secret] --yauth:login/passwd [--return:body|boolean|object] [--host:host] [--api:path]
13
+
14
+ Enjoy...
15
+
16
+ END
17
+
18
+ end
19
+
20
+ arg = ARGV
21
+ if arg.size>0
22
+ consumer = arg.select{|x|/^--consumer/=~x}[0]
23
+ yauth = arg.select{|x|/^--yauth/=~x}[0]
24
+ retrn = arg.select{|x|/^--return/=~x}[0]
25
+ host = arg.select{|x|/^--host/=~x}[0]
26
+ api = arg.select{|x|/^--api/=~x}[0]
27
+
28
+ cons = consumer.split(':')[1].split('/')
29
+ yths = yauth.split(':')[1].split('/')
30
+
31
+ require 'rubygems'
32
+ require 'oa_test'
33
+
34
+ OA = oa = OAuthTest.new(
35
+ :key => cons[0].strip,
36
+ :secret => cons[1].strip,
37
+ :return => (retrn ? retrn.to_sym : :body)
38
+ ).yauth(
39
+ :login => yths[0].strip,
40
+ :passwd => yths[1].strip
41
+ )
42
+
43
+ # add constanta and action...
44
+ class Object
45
+ def oa
46
+ OA
47
+ end
48
+ end
49
+
50
+ # remove non irb arguments...
51
+ ARGV.clear
52
+ (arg - [consumer,yauth,retrn,host,api].compact).each do |v|
53
+ ARGV.push v
54
+ end
55
+
56
+ require 'irb'
57
+ puts ''
58
+ puts "PATH: #{oa.host}#{oa.api}<path>"
59
+ puts "Your instance object stored in OA|oa"
60
+ puts "Ex: oa.get '/me.json'"
61
+ puts ''
62
+
63
+ IRB.start
64
+ else
65
+ howto_oa_test
66
+ end
@@ -0,0 +1,83 @@
1
+ require 'OAuth'
2
+ require 'HTTParty'
3
+ require 'active_support'
4
+
5
+ class OAuthTest
6
+ attr_accessor :host,:api
7
+
8
+ def initialize(ks)
9
+ @key = ks[:key]
10
+ @secret = ks[:secret]
11
+ @return = ks[:return]
12
+ @host = ks[:host] ? ks[:host] : 'http://www.koprol.com'
13
+ @api = ks[:api] ? ks[:api] : '/api/v2'
14
+ @typ = {
15
+ :json => {"Accept" => "application/json", "Content-Type" => "application/json"},
16
+ :xml => {"Accept" => "application/xml", "Content-Type" => "application/xml"},
17
+ }
18
+ end
19
+
20
+ def yauth(lp)
21
+ get_part(lp).get_token()
22
+ end
23
+
24
+ def get(path)
25
+ rtn @access_token.get(@host+@api+path,typ(path))
26
+ end
27
+
28
+ def post(path,params)
29
+ rtn @access_token.post(@host+@api+path,params.to_json,typ(path))
30
+ end
31
+
32
+ def put(path,params)
33
+ rtn @access_token.put(@host+@api+path,params.to_json,typ(path))
34
+ end
35
+
36
+ def delete(path)
37
+ rtn @access_token.delete(@host+@api+path,typ(path))
38
+ end
39
+
40
+ protected
41
+
42
+ def get_part(lp)
43
+ url = "https://login.yahoo.com/WSLogin/V1/get_auth_token"
44
+ content = {:query=>{:oauth_consumer_key=>@key, :passwd=>lp[:passwd], :login=>lp[:login]}}
45
+ @part = HTTParty.get(url, content).parsed_response.split('=')[1].gsub("\n","")
46
+ self
47
+ end
48
+
49
+ def get_token
50
+ consumer = OAuth::Consumer.new(@key,@secret, { :site => "https://api.login.yahoo.com", :access_token_path => "/oauth/v2/get_token" })
51
+ req_token = OAuth::RequestToken.new(consumer, @part)
52
+ token_hash = consumer.token_request(:post, "/oauth/v2/get_token", req_token)
53
+ @access_token= OAuth::AccessToken.new(consumer,token_hash["oauth_token"],token_hash["oauth_token_secret"])
54
+ self
55
+ end
56
+
57
+ def typ(path)
58
+ ext = path[/.(json|xml)($|\?)/,1]
59
+ ext = 'json' if !ext
60
+ @typ[ext.to_sym]
61
+ end
62
+
63
+ def rtn(resp)
64
+ if @return==nil || @return==:boolean
65
+ resp.class==Net::HTTPOK
66
+ elsif @return==:body
67
+ resp.body
68
+ elsif @return==:object
69
+ resp
70
+ end
71
+ end
72
+
73
+ end
74
+ # oa_test --consumer:dj0yJmk9dmhUeEk3ZzRRRVdtJmQ9WVdrOVdFd3pZV3hKTkhVbWNHbzlNVEF3T0Rrek56WXkmcz1jb25zdW1lcnNlY3JldCZ4PTU3/0efbd3fc95a5c0b77d54481b42e8dfb333ed80aa --yauth:ronald_winda/ronald_ganteng
75
+ oa = OAuthTest.new(
76
+ :key => 'dj0yJmk9dmhUeEk3ZzRRRVdtJmQ9WVdrOVdFd3pZV3hKTkhVbWNHbzlNVEF3T0Rrek56WXkmcz1jb25zdW1lcnNlY3JldCZ4PTU3',
77
+ :secret => '0efbd3fc95a5c0b77d54481b42e8dfb333ed80aa',
78
+ :return => :body
79
+ ).yauth(
80
+ :login => "ronald_winda",
81
+ :passwd => "ronald_ganteng"
82
+ )
83
+ oa.post('/streams.json',:stream => {:text => "test"})
@@ -0,0 +1,3 @@
1
+ module Capykit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/oa_test.rb ADDED
@@ -0,0 +1,2 @@
1
+ files =Dir[File.join(File.dirname(__FILE__),%w[.. lib oa_test ** *.rb])]
2
+ files.each{ |f|require(f) }
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa_test
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Watchmen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-22 00:00:00 +07:00
19
+ default_executable: oa_test
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: oauth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 0
32
+ - 4
33
+ - 1
34
+ version: 0.4.1
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: httparty
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 5
46
+ segments:
47
+ - 0
48
+ - 6
49
+ - 1
50
+ version: 0.6.1
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: OAuth mini test for yahoo property
54
+ email:
55
+ - watchmencore@yahoo.com
56
+ executables:
57
+ - oa_test
58
+ extensions: []
59
+
60
+ extra_rdoc_files: []
61
+
62
+ files:
63
+ - lib/oa_test/oa_test.rb
64
+ - lib/oa_test/version.rb
65
+ - lib/oa_test.rb
66
+ - bin/oa_test
67
+ has_rdoc: true
68
+ homepage: http://www.github.com/watchmen
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 21
91
+ segments:
92
+ - 1
93
+ - 3
94
+ - 7
95
+ version: 1.3.7
96
+ requirements: []
97
+
98
+ rubyforge_project: oa_test
99
+ rubygems_version: 1.4.2
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: OAuth mini test
103
+ test_files: []
104
+