twumper 0.1.1

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
+ SHA256:
3
+ metadata.gz: 998cdfa3565aa5cdcb5cbd013daae08d6851cdb787ed6b2b136effc3610e76f5
4
+ data.tar.gz: 495166a0359e749e863660cd3f5572cd3c15bf009883b8c7298c90f400648a9f
5
+ SHA512:
6
+ metadata.gz: efe486ae7a04671e56ba722f3136886b411dd63ba6091eaae84d331fedffc1ee34a4fb6f86cf101c00d56d1969c58b2e14eb343ecd951f95f8452e8633ea7ddc
7
+ data.tar.gz: 5f70ad4cbf082125c36b3ce8acc4fdac2e3248687c6e4c366e7cacb714ad67e1fc95f4e3050dcddc0ce9437365d70671b4cbbde9fbf15b1ff9f99a11ca402f4c
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .DS_Store
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.5
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in twumper.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ twumper (0.1.0)
5
+ httparty (~> 0.13.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (10.0.2)
11
+ diff-lcs (1.3)
12
+ httparty (0.13.7)
13
+ json (~> 1.8)
14
+ multi_xml (>= 0.5.2)
15
+ json (1.8.6)
16
+ multi_xml (0.6.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.16)
37
+ byebug
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+ twumper!
41
+
42
+ BUNDLED WITH
43
+ 1.16.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 zayneio
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,41 @@
1
+ # Twumper
2
+
3
+ Twumper is a simple gem to interface with the Twitter API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'twumper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install twumper
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ twumper = Twumper.new
25
+
26
+ #set consumer key and secret values
27
+ twumper.config do |tw|
28
+ tw.consumer_key = YOUR_CONSUMER_KEY
29
+ tw.consumer_secret = YOUR_CONSUMER_SECERET
30
+ end
31
+
32
+ # retrieve and set your bearer token
33
+ twumper.get_bearer
34
+
35
+ # search for a keyword and retrieve related tweets
36
+ twumper.search('christmas')
37
+ ```
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "twumper"
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(__FILE__)
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/lib/twumper.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "twumper/client"
2
+
3
+ module Twumper
4
+ class << self
5
+
6
+ def new
7
+ @client ||= Twumper::Client.new
8
+ end
9
+
10
+ def respond_to?(method, include_private = false)
11
+ new.respond_to?(method, include_private) || super
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'config'
2
+ require_relative 'connection'
3
+ require_relative 'request'
4
+ require_relative 'response'
5
+ require_relative 'search'
6
+
7
+ module Twumper
8
+ class Client
9
+ include Twumper::Config
10
+ include Twumper::Connection
11
+ include Twumper::Request
12
+ include Twumper::Response
13
+ include Twumper::Search
14
+
15
+ def initialize
16
+ reset
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,47 @@
1
+ module Twumper
2
+ module Config
3
+
4
+ attr_accessor :headers, :consumer_key, :consumer_secret, :bearer
5
+
6
+ def config
7
+ yield self
8
+ end
9
+
10
+ def reset
11
+ self.headers = nil
12
+ self.consumer_key = nil
13
+ self.consumer_secret = nil
14
+ self.bearer = nil
15
+ self
16
+ end
17
+
18
+ def get_bearer
19
+ self.bearer = build_bearer_request
20
+ end
21
+
22
+ def build_bearer_request
23
+ credentials = set_credentials
24
+ url = "https://api.twitter.com/oauth2/token"
25
+ body = "grant_type=client_credentials"
26
+ headers = set_headers(credentials)
27
+ request_bearer(url, body, headers)
28
+ end
29
+
30
+ def set_credentials
31
+ credentials = Base64.encode64("#{self.consumer_key}:#{self.consumer_secret}").gsub("\n", '')
32
+ end
33
+
34
+ def set_headers(credentials=nil)
35
+ if self.bearer.nil? && credentials
36
+ self.headers = { "Authorization" => "Basic #{credentials}" }
37
+ else
38
+ self.headers = { "Authorization" => "Bearer #{self.bearer}" }
39
+ end
40
+ end
41
+
42
+ def request_bearer(url, body, headers)
43
+ resp = connection.post(url, body: body, headers: headers)
44
+ bearer_token = resp['access_token']
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,9 @@
1
+ require 'httparty'
2
+
3
+ module Twumper
4
+ module Connection
5
+ def connection
6
+ HTTParty
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'response'
2
+
3
+ module Twumper
4
+ module Request
5
+ def get(url, options = {})
6
+ request(:get, url, options)
7
+ end
8
+
9
+ def post(url, options = {})
10
+ request(:post, url, options)
11
+ end
12
+
13
+ private
14
+
15
+ def request(method, url, options)
16
+ case method
17
+ when :get
18
+ response = connection.get(url, headers: headers)
19
+ when :post
20
+ response = connection.post(url, body: body, headers: headers)
21
+ end
22
+ # build(response.body)
23
+ response.body
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Twumper
2
+ module Response
3
+ def build(body)
4
+ body
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ module Twumper
2
+ module Search
3
+
4
+ BASE_URL = "https://api.twitter.com/1.1/search/tweets.json"
5
+ DEFAULT_OPTIONS = {
6
+ count: 100,
7
+ limit: 200,
8
+ result_type: 'mixed',
9
+ max_id: nil
10
+ }
11
+
12
+ def search(keyword, options=DEFAULT_OPTIONS)
13
+ tweets = Array.new
14
+ while tweets.count < options[:limit]
15
+ url = "#{BASE_URL}?q=#{keyword}&result_type=#{options[:result_type]}&count=#{options[:count]}"
16
+ url += "&max_id=#{options[:max_id]}" if !options[:max_id].nil?
17
+ headers = set_headers
18
+ response = connection.get(url, headers: headers)
19
+ tweets += response['statuses']
20
+ options[:max_id] = tweets.last['id']
21
+ end
22
+ tweets
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Twumper
2
+ VERSION = "0.1.1"
3
+ end
data/twumper.gemspec ADDED
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "twumper/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twumper"
8
+ spec.version = Twumper::VERSION
9
+ spec.authors = ["zayne"]
10
+ spec.email = ["hello@zayne.io"]
11
+
12
+ spec.summary = %q{Write a short summary, because RubyGems requires one.}
13
+ spec.description = %q{Write a longer description or delete this line.}
14
+ spec.homepage = "https://rubygems.org"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_dependency "httparty", "~> 0.13.7"
39
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twumper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - zayne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.13.7
69
+ description: Write a longer description or delete this line.
70
+ email:
71
+ - hello@zayne.io
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/twumper.rb
87
+ - lib/twumper/client.rb
88
+ - lib/twumper/config.rb
89
+ - lib/twumper/connection.rb
90
+ - lib/twumper/request.rb
91
+ - lib/twumper/response.rb
92
+ - lib/twumper/search.rb
93
+ - lib/twumper/version.rb
94
+ - twumper.gemspec
95
+ homepage: https://rubygems.org
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ allowed_push_host: https://rubygems.org
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.6
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Write a short summary, because RubyGems requires one.
120
+ test_files: []