simple_twitter_oauth 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: 664435a3eff5683bf4db78ca51f1d676eb1252c1
4
+ data.tar.gz: c21379f64972f61df86a76d96ebe4bd390ecfdec
5
+ SHA512:
6
+ metadata.gz: 5df6717a828fcf742e5a5c63a2c6d698de3ac6def5cb2eb6692bed19f84674b457fe65c9d07d7951d9c0ca0c8d7c7d5f71b6a33c6aa2ae5431315ca0432bf900
7
+ data.tar.gz: 3358772aef5c4f70c5c53a74b3515165e9796c558c6ab932aad23db0e17781a0b32ce54042dc801cb2505509ee013d4fb77c9908fc674518a472a2de43df39e0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /pkg/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.5
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at odindutton@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Odin Dutton
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Simple Twitter OAuth
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ``` ruby
8
+ gem 'simple_twitter_oauth'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ``` ruby
14
+ request_token = SimpleTwitterOAuth.get_request_token(
15
+ consumer_key: 'abc123',
16
+ consumer_secret: 'def456',
17
+ callback_url: 'https://example.com/callback',
18
+ )
19
+
20
+ session[:token] = request_token.token
21
+ session[:token_secret] = request_token.secret
22
+
23
+ redirect_to request_token.authorize_url
24
+ ```
25
+
26
+ ``` ruby
27
+ access_token = SimpleTwitterOAuth.get_access_token(
28
+ consumer_key: 'abc123',
29
+ consumer_secret: 'def456',
30
+ token: session.delete(:token),
31
+ token_secret: session.delete(:token_secret),
32
+ oauth_verifier: params[:oauth_verifier],
33
+ )
34
+
35
+ if access_token
36
+ # These are the methods available on AccessToken:
37
+ #
38
+ # access_token.screen_name
39
+ # access_token.token
40
+ # access_token.secret
41
+
42
+ redirect_to account_path, success: 'Account added successfully'
43
+ else
44
+ redirect_to account_path, alert: 'Adding account failed'
45
+ end
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies.
51
+ Then, run `rake` to run the tests.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`.
54
+ To release a new version, update the version number in `version.rb`,
55
+ and then run `bundle exec rake release`,
56
+ which will create a git tag for the version,
57
+ push git commits and tags,
58
+ and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/twe4ked/simple_twitter_oauth This project is intended to be a safe,
63
+ welcoming space for collaboration,
64
+ and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new :spec do |task|
5
+ task.verbose = false
6
+ end
7
+
8
+ task default: :spec
@@ -0,0 +1,13 @@
1
+ module SimpleTwitterOAuth
2
+ class AccessToken
3
+ attr_reader :screen_name, :token, :secret
4
+
5
+ # @api private
6
+ def initialize(screen_name:, token:, secret:)
7
+ @screen_name = screen_name
8
+ @token = token
9
+ @secret = secret
10
+ freeze
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module SimpleTwitterOAuth
2
+ class RequestToken
3
+ attr_reader :token, :secret, :authorize_url
4
+
5
+ # @api private
6
+ def initialize(token:, secret:, authorize_url:)
7
+ @token = token
8
+ @secret = secret
9
+ @authorize_url = authorize_url
10
+ freeze
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleTwitterOAuth
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,53 @@
1
+ require 'simple_twitter_oauth/version'
2
+ require 'simple_twitter_oauth/request_token'
3
+ require 'simple_twitter_oauth/access_token'
4
+
5
+ require 'oauth'
6
+
7
+ module SimpleTwitterOAuth
8
+ SITE = 'https://twitter.com'
9
+
10
+ # This method is used to before sending the user to Twitter for authentication.
11
+ #
12
+ # @param consumer_key [String] the Twitter application's consumer key
13
+ # @param consumer_secret [String] the Twitter application's consumer secret
14
+ # @param callback_url [String] the URL that Twitter will call after the user has authenticated
15
+ # @return [SimpleTwitterOAuth::RequestToken] an object with a token, secret, and authorize_url
16
+ def self.get_request_token(consumer_key:, consumer_secret:, callback_url:)
17
+ consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site: SITE)
18
+ request_token = consumer.get_request_token(oauth_callback: callback_url)
19
+
20
+ RequestToken.new(
21
+ token: request_token.token,
22
+ secret: request_token.secret,
23
+ authorize_url: request_token.authorize_url(oauth_callback: callback_url),
24
+ )
25
+ end
26
+
27
+ # This method is used after the user has authenticated with Twitter.
28
+ #
29
+ # @param consumer_key [String] the Twitter application's consumer key
30
+ # @param consumer_secret [String] the Twitter application's consumer secret
31
+ # @param token [String] the token returned from get_request_token
32
+ # @param token_secret [String] the secret returned from get_request_token
33
+ # @param oauth_verifier [String] the oauth_verifier param from the callback URL
34
+ # @return [SimpleTwitterOAuth::AccessToken, nil] an object with a screen_name, token, and secret, or nil
35
+ def self.get_access_token(consumer_key:, consumer_secret:, token:, token_secret:, oauth_verifier:)
36
+ consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site: SITE)
37
+ request_token = OAuth::RequestToken.from_hash(consumer,
38
+ oauth_token: token,
39
+ oauth_token_secret: token_secret,
40
+ )
41
+
42
+ begin
43
+ access_token = request_token.get_access_token(oauth_verifier: oauth_verifier)
44
+
45
+ AccessToken.new(
46
+ screen_name: access_token.params[:screen_name],
47
+ token: access_token.token,
48
+ secret: access_token.secret,
49
+ )
50
+ rescue OAuth::Unauthorized
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'simple_twitter_oauth/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'simple_twitter_oauth'
10
+ spec.version = SimpleTwitterOAuth::VERSION
11
+ spec.authors = ['Odin Dutton']
12
+ spec.email = ['odindutton@gmail.com']
13
+ spec.summary = 'A really simple Twitter OAuth library.'
14
+ spec.homepage = 'https://github.com/twe4ked/simple_twitter_oauth'
15
+ spec.license = 'MIT'
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'oauth', '~> 0.5.1'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.13'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_twitter_oauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Odin Dutton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-04 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.1
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.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - odindutton@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/simple_twitter_oauth.rb
85
+ - lib/simple_twitter_oauth/access_token.rb
86
+ - lib/simple_twitter_oauth/request_token.rb
87
+ - lib/simple_twitter_oauth/version.rb
88
+ - simple_twitter_oauth.gemspec
89
+ homepage: https://github.com/twe4ked/simple_twitter_oauth
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: A really simple Twitter OAuth library.
113
+ test_files: []