last_tweet_redux 0.1.0
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 +7 -0
- data/bin/last-tweet +26 -0
- data/lib/last_tweet_redux/configuration.rb +20 -0
- data/lib/last_tweet_redux/connection.rb +47 -0
- data/lib/last_tweet_redux/formatter.rb +14 -0
- data/lib/last_tweet_redux/job.rb +27 -0
- data/lib/last_tweet_redux/oauth_header.rb +11 -0
- data/lib/last_tweet_redux/version.rb +3 -0
- data/lib/last_tweet_redux.rb +24 -0
- metadata +124 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5443c6fa73dc44356cc8852d3002a8e5c63415cc
|
|
4
|
+
data.tar.gz: 1c09dc614d059efbf65c4e1b36fc2c4fae45d9f2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: aefa7f5c7ec5a5c35fcbc14c0d141786a29042302d8b96aa1d702044ab4635b665b348873cdbe4b12855831d2bba27866e73b0712e57351a080ddb0fb4d25802
|
|
7
|
+
data.tar.gz: 8fea40173bba14d10c11f95c0ad39a30422331670c3113a31381b88de7155ff3564dc70465e8fcc8074397c15edd49938b7d481b6da2dc1c6f4ebb0614615471
|
data/bin/last-tweet
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'dante'
|
|
4
|
+
require File.expand_path("../../lib/last_tweet_redux", __FILE__)
|
|
5
|
+
|
|
6
|
+
runner = Dante::Runner.new('last_tweet_redux')
|
|
7
|
+
runner.description = 'Last Tweet Redux'
|
|
8
|
+
|
|
9
|
+
runner.with_options do |opts|
|
|
10
|
+
opts.on('-c', '--config FILE.yml', String, 'Config path') do |test|
|
|
11
|
+
options[:config] = test
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Create validation hook for options
|
|
16
|
+
runner.verify_options_hook = lambda do |opts|
|
|
17
|
+
raise Exception.new('Must supply config parameter') if opts[:config].nil?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
runner.execute do |opts|
|
|
21
|
+
# opts: host, pid_path, port, daemonize, user, group
|
|
22
|
+
puts opts[:config]
|
|
23
|
+
puts opts[:pid_path]
|
|
24
|
+
|
|
25
|
+
LastTweetRedux::Process.init(opts[:config])
|
|
26
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'active_support/core_ext/hash'
|
|
2
|
+
require 'active_support/core_ext/integer'
|
|
3
|
+
|
|
4
|
+
module LastTweetRedux
|
|
5
|
+
class Configuration
|
|
6
|
+
attr_accessor :screen_name
|
|
7
|
+
attr_accessor :redis_url
|
|
8
|
+
attr_accessor :oauth_credentials
|
|
9
|
+
attr_accessor :interval
|
|
10
|
+
|
|
11
|
+
def initialize(config_path)
|
|
12
|
+
credentials = YAML.load_file(config_path).symbolize_keys
|
|
13
|
+
|
|
14
|
+
self.oauth_credentials = credentials.fetch(:oauth).symbolize_keys
|
|
15
|
+
self.screen_name = credentials.fetch(:screen_name)
|
|
16
|
+
self.redis_url = credentials.fetch(:redis_url)
|
|
17
|
+
self.interval = credentials.fetch(:interval).to_i.minutes
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module LastTweetRedux
|
|
6
|
+
class Connection
|
|
7
|
+
BASE_TWITTER_API = 'https://api.twitter.com/1.1'
|
|
8
|
+
USER_TIMELINE_API = "#{BASE_TWITTER_API}/statuses/user_timeline.json"
|
|
9
|
+
|
|
10
|
+
def initialize(screen_name, oauth_credentials)
|
|
11
|
+
@uri_query_params = default_uri_query_params(screen_name)
|
|
12
|
+
@oauth_credentials = oauth_credentials
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def retrieve_tweet
|
|
16
|
+
headers = authorization_header(USER_TIMELINE_API, @uri_query_params, @oauth_credentials)
|
|
17
|
+
uri = URI(USER_TIMELINE_API).tap { |u| u.query = URI.encode_www_form(@uri_query_params) }
|
|
18
|
+
response = run_get_request(uri, headers)
|
|
19
|
+
|
|
20
|
+
JSON.parse(response.body).first
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def run_get_request(uri, headers)
|
|
26
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
27
|
+
http.use_ssl = true
|
|
28
|
+
|
|
29
|
+
request = Net::HTTP::Get.new(uri)
|
|
30
|
+
headers.each do |header, value|
|
|
31
|
+
request[header] = value
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
http.request(request)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def authorization_header(uri, uri_query_params, oauth_credentials)
|
|
38
|
+
oauth_header = OauthHeader.create(uri, uri_query_params, oauth_credentials)
|
|
39
|
+
|
|
40
|
+
{ 'Authorization' => oauth_header.to_s }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def default_uri_query_params(screen_name)
|
|
44
|
+
{ count: 1, screen_name: screen_name, exclude_replies: true }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'twitter-text'
|
|
2
|
+
|
|
3
|
+
module LastTweetRedux
|
|
4
|
+
module Formatter extend self
|
|
5
|
+
extend Twitter::Autolink
|
|
6
|
+
|
|
7
|
+
def process(raw_tweet)
|
|
8
|
+
{
|
|
9
|
+
body: auto_link(raw_tweet['text'], target: '_blank', url_entities: raw_tweet['entities']['urls']),
|
|
10
|
+
created_at: raw_tweet['created_at']
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'redis'
|
|
2
|
+
|
|
3
|
+
module LastTweetRedux
|
|
4
|
+
class Job
|
|
5
|
+
def initialize(opts)
|
|
6
|
+
@options = opts
|
|
7
|
+
@client = opts.redis_url ? Redis.new : Redis.new(url: opts.redis_url)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def run
|
|
11
|
+
last_tweet = connection.retrieve_tweet
|
|
12
|
+
formatted_last_tweet = Formatter.process(last_tweet)
|
|
13
|
+
|
|
14
|
+
save(formatted_last_tweet.to_json)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def connection
|
|
20
|
+
@connection ||= Connection.new(@options.screen_name, @options.oauth_credentials)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def save(html)
|
|
24
|
+
@client.set('last_tweet', html)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_relative 'last_tweet_redux/configuration'
|
|
2
|
+
require_relative 'last_tweet_redux/oauth_header'
|
|
3
|
+
require_relative 'last_tweet_redux/connection'
|
|
4
|
+
require_relative 'last_tweet_redux/formatter'
|
|
5
|
+
require_relative 'last_tweet_redux/job'
|
|
6
|
+
|
|
7
|
+
module LastTweetRedux
|
|
8
|
+
module Process extend self
|
|
9
|
+
def init(config_path)
|
|
10
|
+
config = Configuration.new(config_path)
|
|
11
|
+
job = Job.new(config)
|
|
12
|
+
|
|
13
|
+
loop do
|
|
14
|
+
job.run
|
|
15
|
+
|
|
16
|
+
puts job.instance_eval { @client.get('last_tweet') }
|
|
17
|
+
|
|
18
|
+
GC.start
|
|
19
|
+
|
|
20
|
+
sleep config.interval
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: last_tweet_redux
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Marian Posaceanu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: redis
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: dante
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.2'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.2'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: simple_oauth
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0.2'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0.2'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: twitter-text
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.9'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.9'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: activesupport
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '4'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '4'
|
|
83
|
+
description: Runs a trivial background process that just fetches the last tweet and
|
|
84
|
+
saves it to a Redis backend this can also be a form of a microservice.
|
|
85
|
+
email:
|
|
86
|
+
- contact@marianposaceanu.com
|
|
87
|
+
executables:
|
|
88
|
+
- last-tweet
|
|
89
|
+
extensions: []
|
|
90
|
+
extra_rdoc_files: []
|
|
91
|
+
files:
|
|
92
|
+
- bin/last-tweet
|
|
93
|
+
- lib/last_tweet_redux.rb
|
|
94
|
+
- lib/last_tweet_redux/configuration.rb
|
|
95
|
+
- lib/last_tweet_redux/connection.rb
|
|
96
|
+
- lib/last_tweet_redux/formatter.rb
|
|
97
|
+
- lib/last_tweet_redux/job.rb
|
|
98
|
+
- lib/last_tweet_redux/oauth_header.rb
|
|
99
|
+
- lib/last_tweet_redux/version.rb
|
|
100
|
+
homepage: https://github.com/dakull/last_tweet_redux
|
|
101
|
+
licenses:
|
|
102
|
+
- MIT
|
|
103
|
+
metadata: {}
|
|
104
|
+
post_install_message:
|
|
105
|
+
rdoc_options: []
|
|
106
|
+
require_paths:
|
|
107
|
+
- lib
|
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - ">="
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0'
|
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
requirements: []
|
|
119
|
+
rubyforge_project:
|
|
120
|
+
rubygems_version: 2.2.2
|
|
121
|
+
signing_key:
|
|
122
|
+
specification_version: 4
|
|
123
|
+
summary: Just fetches your last tweet and saves it to Redis
|
|
124
|
+
test_files: []
|