tjplurk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 398334d936a13c800d8c6a8a53d7bc5e75a440ca
4
+ data.tar.gz: ee2c577d64529d0e0168528f8486fe9d35be75ce
5
+ SHA512:
6
+ metadata.gz: 10b0352ccc8a7f9ce921957ce95ad1af92698fa5b9faea9ec6cab6c86b2fae8603aa966c2f6233919300b5eadb7c8eecb1e60f77ee8bc907ccc8ba13b3504a53
7
+ data.tar.gz: ec703d4400428c658744dd2fa37f6ba3f02e3862286740cd9ef0a59f2a04102fca5d2ea57220dec7ef0ce1a875beceb748e01d5d82dd944c36059f1875a17efb
data/bin/tjplurk ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'tjplurk/cli'
3
+ Tjplurk::Cli.start(ARGV)
@@ -0,0 +1,25 @@
1
+ require 'oauth'
2
+ require 'json'
3
+
4
+ module Tjplurk
5
+ class API
6
+ attr_reader :consumer, :request_token, :access_token
7
+
8
+ def initialize(consumer_key = nil, consumer_secret = nil, token_key = nil, token_secret = nil)
9
+ if consumer_key.nil? || consumer_secret.nil?
10
+ raise 'Consumer key & secret are not found.' unless File.exist? TJPLURK_FILE
11
+ consumer_key, consumer_secret, token_key, token_secret = File.readlines(TJPLURK_FILE).map(&:strip!).delete_if(&:empty?)
12
+ end
13
+ @consumer = OAuth::Consumer.new(consumer_key, consumer_secret, Tjplurk::OAUTH_OPTIONS)
14
+ @access_token = OAuth::AccessToken.new(@consumer, token_key, token_secret) if token_key && token_secret
15
+ end
16
+
17
+ def request_token
18
+ @request_token ||= @consumer.get_request_token
19
+ end
20
+
21
+ def request path, body = '', headers = {}
22
+ JSON.parse(@access_token.post(path, body, headers).body)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,39 @@
1
+ require 'launchy'
2
+ require 'tjplurk'
3
+ require 'thor'
4
+
5
+ module Tjplurk
6
+ class Cli < Thor
7
+ include Thor::Actions
8
+
9
+ desc 'auth CONSUMER_KEY CONSUMER_SECRET', 'get access token interactivly.'
10
+ def auth consumer_key, consumer_secret
11
+ api = Tjplurk::API.new(consumer_key, consumer_secret)
12
+ puts "Authorize URL: #{api.request_token.authorize_url}"
13
+ Launchy.open(api.request_token.authorize_url)
14
+ oauth_verifier = ask 'Enter Verification Number:'
15
+ access_token = api.request_token.get_access_token oauth_verifier: oauth_verifier
16
+ File.open(Tjplurk::TJPLURK_FILE, 'w') do |f|
17
+ f.puts consumer_key
18
+ f.puts consumer_secret
19
+ f.puts access_token.token
20
+ f.puts access_token.secret
21
+ end
22
+ puts "Key & secret successfully saved to \"#{Tjplurk::TJPLURK_FILE}\"."
23
+ end
24
+
25
+ desc 'api PATH ["FOO=BAR" ...]', 'send an API request.'
26
+ long_desc <<-LONGDESC
27
+ For example:
28
+ \x5$ tjplurk api /APP/Users/me
29
+ \x5$ tjplurk api /APP/Timeline/plurkAdd "content=hello world" qualifier=says
30
+
31
+ For more available paths, see http://www.plurk.com/API'
32
+ LONGDESC
33
+ def api path, *args
34
+ params = Hash[args.map{|arg| arg.split('=')}]
35
+ api = Tjplurk::API.new
36
+ puts api.access_token.post(path, params).body
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Tjplurk
2
+ VERSION = '1.0.0'
3
+ end
data/lib/tjplurk.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'tjplurk/api'
2
+
3
+ module Tjplurk
4
+ OAUTH_OPTIONS = {
5
+ site: 'http://www.plurk.com',
6
+ request_token_path: '/OAuth/request_token',
7
+ access_token_path: '/OAuth/access_token',
8
+ authorize_path: '/OAuth/authorize'
9
+ }
10
+
11
+ TJPLURK_FILE = File.join(ENV['HOME'], '.tjplurk')
12
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tjplurk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tony Jian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: launchy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Plurk API Wrapper
70
+ email: tonytonyjan@gmail.com
71
+ executables:
72
+ - tjplurk
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - bin/tjplurk
77
+ - lib/tjplurk.rb
78
+ - lib/tjplurk/api.rb
79
+ - lib/tjplurk/cli.rb
80
+ - lib/tjplurk/version.rb
81
+ homepage: https://github.com/tonytonyjan/tjplurk
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.3.0
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Plurk API Wrapper
105
+ test_files: []