twitter_oauth_token 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b0f0b00daecf76eb790c4f64a083329589fdf72d
4
+ data.tar.gz: 2f072be25adabf202f5821ec739e7c59aa215e59
5
+ SHA512:
6
+ metadata.gz: a523160299c3269cc0fa33e697b9d14a16d8147c850d2b6497d2bc6b7ad251da7a6e8f8915299a5508d14e238a28ae2b489aea968b948dceaba327503b1931a5
7
+ data.tar.gz: 50a3488e028053f132b3afa2ad8f209740d78513f913f5c1f31a0ec217ecf52b226373a0b56462bb95c5d9921eea79d95e94198c4f3ee4686933bb0d09725251
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in twitter_oauth_token.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # twitter_oauth_token
2
+
3
+ Gimme that Twitter OAuth access token!
4
+
5
+ ![](http://i.giphy.com/CDoxe35inxhfO.gif)
6
+
7
+ [![Circle CI](https://img.shields.io/circleci/project/dkhamsing/twitter_oauth_token.svg)](https://circleci.com/gh/dkhamsing/twitter_oauth_token)
8
+
9
+ This is the library version of the [`get-twitter-oauth-token`](#credits) command line tool :sweat_smile:
10
+
11
+ ## Installation
12
+
13
+ ```shell
14
+ $ git clone https://github.com/dkhamsing/twitter_oauth_token.git
15
+ $ cd twitter_oauth_token/
16
+ $ rake install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```shell
22
+ $ irb
23
+ irb(main):001:0> require 'twitter_oauth_token'
24
+ => true
25
+ irb(main):002:0> TwitterOAuthToken::get
26
+ [Step 1 of 4] consumer key: ...
27
+ [Step 2 of 4] consumer secret: ...
28
+ [Step 3 of 4] open this link in a browser (sign in and authorize): https://api.twitter.com/oauth/authorize?oauth_token=jKbOtQAAAAAAt_QtAAABU1NHQWU
29
+ [Step 4 of 4] enter pin: 1374423
30
+ => {"access_token"=>"...", "access_token_secret"=>"...", "error"=>nil}
31
+ ```
32
+
33
+ :tada:
34
+
35
+ ### Custom Prompts
36
+
37
+ ```ruby
38
+ prompts = {
39
+ TwitterOAuthToken::PROMPT_CONSUMER_KEY => 'Enter Twitter app consumer key: ',
40
+ TwitterOAuthToken::PROMPT_CONSUMER_SECRET => 'Enter Twitter app consumer secret: ',
41
+ TwitterOAuthToken::PROMPT_OPEN_URL => 'Paste this URL in your browser: ',
42
+ TwitterOAuthToken::PROMPT_PIN => 'What\'s the pin? '
43
+ }
44
+
45
+ TwitterOAuthToken::get(prompts)
46
+ Enter Twitter app consumer key: ...
47
+ # ...
48
+ ```
49
+
50
+ ### Examples
51
+
52
+ - [test](https://github.com/dkhamsing/twitter_oauth_token/blob/stable/test/authorize_url_test.rb)
53
+ - [`update_profile_pic`](https://github.com/dkhamsing/update_profile_pic/blob/dev/lib/update_profile_pic/config_create.rb)
54
+
55
+ ## Credits
56
+
57
+ - [`get-twitter-oauth-token`](https://github.com/jugyo/get-twitter-oauth-token)
58
+ - [giphy](http://gph.is/1qBDfhu)
59
+
60
+ ## Contact
61
+
62
+ - [github.com/dkhamsing](https://github.com/dkhamsing)
63
+ - [twitter.com/dkhamsing](https://twitter.com/dkhamsing)
64
+
65
+ ## License
66
+
67
+ This project is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'twitter_oauth_token'
5
+ TwitterOAuthToken.cli
@@ -0,0 +1,8 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.2.0
4
+ test:
5
+ pre:
6
+ - rake install
7
+ override:
8
+ - ruby test/authorize_url_test.rb
@@ -0,0 +1,5 @@
1
+ require "twitter_oauth_token/cli"
2
+
3
+ # Get Twitter OAuth token
4
+ module TwitterOAuthToken
5
+ end
@@ -0,0 +1,26 @@
1
+ # Command line interface
2
+ module TwitterOAuthToken
3
+ require 'twitter_oauth_token/get'
4
+ require 'twitter_oauth_token/version'
5
+
6
+ class << self
7
+ def cli
8
+ puts "#{PROJECT} #{VERSION}"
9
+ puts 'Let\'s get that token in 4 easy steps!'
10
+ results = get()
11
+
12
+ error = results[RESULT_ERROR]
13
+
14
+ if error.nil?
15
+ access_token = results[RESULT_ACCESS_TOKEN]
16
+ access_token_secret = results[RESULT_ACCESS_TOKEN_SECRET]
17
+
18
+ puts "Token: #{access_token}"
19
+ puts "Secret: #{access_token_secret}"
20
+ puts '🎉'
21
+ else
22
+ puts "Error: #{error}"
23
+ end
24
+ end # cli
25
+ end # class
26
+ end
@@ -0,0 +1,88 @@
1
+ # Get Twitter OAuth token
2
+ module TwitterOAuthToken
3
+ require 'oauth'
4
+
5
+ RESULT_ACCESS_TOKEN = 'access_token'
6
+ RESULT_ACCESS_TOKEN_SECRET = 'access_token_secret'
7
+ RESULT_ERROR = 'error'
8
+
9
+ # prompt keys
10
+ PROMPT_CONSUMER_KEY = 'consumer_key'
11
+ PROMPT_CONSUMER_SECRET = 'consumer_secret'
12
+ PROMPT_PIN = 'pin'
13
+ PROMPT_OPEN_URL = 'open_url'
14
+
15
+ # prompt defaults
16
+ PROMPT_CONSUMER_KEY_DEFAULT = '[Step 1 of 4] consumer key: '
17
+ PROMPT_CONSUMER_SECRET_DEFAULT = '[Step 2 of 4] consumer secret: '
18
+ PROMPT_OPEN_URL_DEFAULT = '[Step 3 of 4] open this link in a browser (sign in and authorize): '
19
+ PROMPT_PIN_DEFAULT = '[Step 4 of 4] enter pin: '
20
+
21
+ class << self
22
+ def consumer(consumer_key, consumer_secret)
23
+ OAuth::Consumer.new(
24
+ consumer_key,
25
+ consumer_secret,
26
+ :site => 'https://api.twitter.com'
27
+ )
28
+ end
29
+
30
+ def request_token(consumer)
31
+ consumer.get_request_token
32
+ end
33
+
34
+ def authorize_url(request_token)
35
+ request_token.authorize_url
36
+ end
37
+
38
+ def access_token(request_token, pin)
39
+ request_token.get_access_token(
40
+ :oauth_token => request_token.token,
41
+ :oauth_verifier => pin
42
+ )
43
+ end
44
+
45
+ def get(prompts=nil)
46
+ if prompts.nil?
47
+ prompts = {
48
+ PROMPT_CONSUMER_KEY => PROMPT_CONSUMER_KEY_DEFAULT,
49
+ PROMPT_CONSUMER_SECRET => PROMPT_CONSUMER_SECRET_DEFAULT,
50
+ PROMPT_OPEN_URL => PROMPT_OPEN_URL_DEFAULT,
51
+ PROMPT_PIN => PROMPT_PIN_DEFAULT
52
+ }
53
+ end
54
+
55
+ begin
56
+ print prompts[PROMPT_CONSUMER_KEY]
57
+ consumer_key = STDIN.gets.strip
58
+
59
+ print prompts[PROMPT_CONSUMER_SECRET]
60
+ consumer_secret = STDIN.gets.strip
61
+
62
+ c = consumer(consumer_key, consumer_secret)
63
+
64
+ request_token = request_token(c)
65
+
66
+ url = authorize_url(request_token)
67
+ puts "#{prompts[PROMPT_OPEN_URL]}#{url}"
68
+
69
+ print prompts[PROMPT_PIN]
70
+ pin = STDIN.gets.strip
71
+
72
+ access_token = access_token(request_token, pin)
73
+
74
+ {
75
+ RESULT_ACCESS_TOKEN => access_token.token,
76
+ RESULT_ACCESS_TOKEN_SECRET => access_token.secret,
77
+ RESULT_ERROR => nil
78
+ }
79
+ rescue => e
80
+ {
81
+ RESULT_ACCESS_TOKEN => nil,
82
+ RESULT_ACCESS_TOKEN_SECRET => nil,
83
+ RESULT_ERROR => e
84
+ }
85
+ end # begin
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,6 @@
1
+ # Project constants
2
+ module TwitterOAuthToken
3
+ VERSION = '0.1.0'
4
+
5
+ PROJECT = 'twitter_oauth_token'
6
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'twitter_oauth_token/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = TwitterOAuthToken::PROJECT
8
+ spec.version = TwitterOAuthToken::VERSION
9
+ spec.authors = ['dkhamsing']
10
+ spec.email = ['dkhamsing8@gmail.com']
11
+
12
+ spec.summary = 'Library to get the Twitter OAuth access token'
13
+ spec.description = 'Based on get-twitter-oauth-token'
14
+ spec.homepage = 'https://github.com/dkhamsing/twitter_oauth_token'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'bin'
19
+ spec.executables = [spec.name]
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'oauth', '~> 0.5.0'
23
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitter_oauth_token
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dkhamsing
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-09 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.5.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.5.0
27
+ description: Based on get-twitter-oauth-token
28
+ email:
29
+ - dkhamsing8@gmail.com
30
+ executables:
31
+ - twitter_oauth_token
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - bin/twitter_oauth_token
41
+ - circle.yml
42
+ - lib/twitter_oauth_token.rb
43
+ - lib/twitter_oauth_token/cli.rb
44
+ - lib/twitter_oauth_token/get.rb
45
+ - lib/twitter_oauth_token/version.rb
46
+ - twitter_oauth_token.gemspec
47
+ homepage: https://github.com/dkhamsing/twitter_oauth_token
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.0.14
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Library to get the Twitter OAuth access token
71
+ test_files: []