twitter-config 1.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d02e34ceaf755ed2fa848aef5898b789c922d17
4
+ data.tar.gz: 598829062733210f289d5d7a53d92e1c3ee5f167
5
+ SHA512:
6
+ metadata.gz: dcea65429403ae9e987af44fb9b92b4a361312efda80d6ea4926a310b16703b625a69276507e01d166c6f3534bd7c9fb7700d817db4aa7d2c1366339e49f7f01
7
+ data.tar.gz: b94f3894dca1648ea47f12d1f3e11b203d97dd2649b66c4d633e7bb914e4af6a6d4bd83f30a9daacd778def3438bc95ee8659b4d2cac9c2ff6d9094556e56dc0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in twitter-config.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nathan Reed
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,60 @@
1
+ # Twitter::Config
2
+
3
+ Lets the twitter gem load its tokens from a config file, instead of having to be specified in code.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'twitter-config'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install twitter-config
20
+
21
+ ## Usage
22
+
23
+ This gem makes it easy to load the user tokens from a config file for the api. It uses the standard `.trc` format from the `t` command line gem. You can use this gem to configure the tokens for new accounts as well.
24
+
25
+ ```ruby
26
+ require 'twitter'
27
+ require 'twitter/config'
28
+
29
+ # if you don't specify the config file it will look for ~/.trc ...
30
+ client = Twitter::REST::Client.from_config('reednj')
31
+
32
+ # but you can specify it explicitly
33
+ client = Twitter::REST::Client.from_config('reednj', :path => "./trc.yaml")
34
+ ```
35
+
36
+ ## Config file format
37
+
38
+ Two file formats are supported - a simpiler that is meant to be manually configured, and the more complicated `.trc` format.
39
+
40
+ The simpler format:
41
+
42
+ ```yaml
43
+ ---
44
+ reednj:
45
+ consumer_key: N5FP6mMnW6cBGdtBsBTLgE81s
46
+ consumer_secret: ...
47
+ access_token: ...
48
+ access_token_secret: ...
49
+ reddit_stream:
50
+ consumer_key: ...
51
+ consumer_secret: ...
52
+ access_token: ...
53
+ access_token_secret: ...
54
+ ```
55
+
56
+ Use the `t` twitter command line client to manage the `.trc` format. If you already have this installed, then you should be able to use `twitter-config` without any configuring anything.
57
+
58
+ ## License
59
+
60
+ 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 "rake/testtask"
3
+ task :default => :spec
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = "test/*_test.rb"
8
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "twitter/config"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/test.rb ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'twitter'
3
+ require 'twitter/config'
4
+
5
+ client = Twitter::REST::Client.from_config('reednj', :path => "#{ENV['HOME']}/.trc")
6
+ puts client.user_timeline.first.text
@@ -0,0 +1,47 @@
1
+ require 'yaml'
2
+ require "twitter/config/version"
3
+
4
+ # The config file should have the following format:
5
+ #
6
+ #---
7
+ # reednj:
8
+ # consumer_key: N5FP6mMnW6cBGdtBsBTLgE81s
9
+ # consumer_secret: LrCTb5Y8JcO5gTvBswACu48p3IqmFPgX2yOG3c45GBh4MtmR1X
10
+ # access_token: 11646642-5jJ7aL5Iq34BA9ZkuiewkkN7GxrTK1v69CnlUcVy1T
11
+ # access_token_secret: dJ3D13bxuN0LvTEVN2JJhvDSmRk8CsgFFB1jGy7MARMJV
12
+ #
13
+ module Twitter::Config
14
+ class YAMLConfig
15
+ def self.for_user(username, options = {})
16
+ path = options[:path] || "#{ENV['HOME']}/.trc"
17
+ config_data = YAML.load_file path
18
+ user_config = {}
19
+
20
+ # we want to be able to handle two different formats - the simple one
21
+ # with just a list of usernames, and the more complicated .trc format
22
+ # that has the app ids in it etc
23
+ if config_data['profiles'].nil?
24
+ user_config = config_data[username]
25
+ else
26
+ user_config = config_data['profiles'][username].values.first
27
+ end
28
+
29
+ raise "no config found for #{username} in file #{path}" if user_config.nil?
30
+ return {
31
+ :consumer_key => user_config['consumer_key'],
32
+ :consumer_secret => user_config['consumer_secret'],
33
+ :access_token => user_config['token'] || user_config['access_token'],
34
+ :access_token_secret => user_config['secret'] || user_config['access_token_secret']
35
+ }
36
+ end
37
+ end
38
+ end
39
+
40
+ module Twitter::REST
41
+ class Client
42
+ def self.from_config(username, options = {})
43
+ trc_config = Twitter::Config::YAMLConfig.for_user username, options
44
+ self.new(trc_config)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Twitter
2
+ module Config
3
+ VERSION = "1.0.3"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'twitter/config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twitter-config"
8
+ spec.version = Twitter::Config::VERSION
9
+ spec.authors = ["Nathan Reed"]
10
+ spec.email = ["reednj@gmail.com"]
11
+
12
+ spec.summary = %q{load twitter credentials from a file for the twitter gem}
13
+ spec.homepage = "https://github.com/reednj/twitter-config"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = '>=1.9.3'
25
+ spec.add_development_dependency 'twitter'
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "test-unit"
29
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitter-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Reed
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: twitter
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: 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: test-unit
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:
70
+ email:
71
+ - reednj@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - bin/test.rb
85
+ - lib/twitter/config.rb
86
+ - lib/twitter/config/version.rb
87
+ - twitter-config.gemspec
88
+ homepage: https://github.com/reednj/twitter-config
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.9.3
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.6.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: load twitter credentials from a file for the twitter gem
112
+ test_files: []