twitter_client_app 0.0.2

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: f8d9644d0f0c0297ed4d2e2da43557b9b517f116
4
+ data.tar.gz: 00a9217d6d6fd9fd997cba93382e2a3e963e2079
5
+ SHA512:
6
+ metadata.gz: 4bd0209bd2da06a856f31a83648fba7ebe894b99bfd9ac01986040a103407054395aa39931875bdada4b841ed12350e181a15258dd07a677cb3c4f00f981b619
7
+ data.tar.gz: 496acae39e0cf6c595aa1817d0d77e35a6715fe78d3469221c5ec2cb3c7bff592740602c84b22ea3fc2e501ad00ab667e50197d961f9090ab87d57fad7df7d61
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in twitter_client_app.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 KAWANO Shinobu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # TwitterClientApp
2
+
3
+ A simple Sinatra app which is integrated with Twitter Oauth login and some of its API.
4
+
5
+ This gem aims for Sencha MokuMoku Meetup 2nd (that be held in Japan at 2014/05/30).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'twitter_client_app'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install twitter_client_app
20
+
21
+ ## Usage
22
+
23
+ Create an app directory, then make Gemfile.
24
+
25
+ mkdir myapp && cd myapp && touch Gemfile
26
+
27
+ Edit Gemfile as followings.
28
+
29
+ # A sample Gemfile
30
+ source "https://rubygems.org"
31
+
32
+ gem 'twitter_client_app'
33
+
34
+ Also make public directory, and put the index.html file. After that, please make app.rb and edit it as following.
35
+
36
+ require 'twitter_client_app'
37
+
38
+ CONSUMER_KEY = "Your Consumer key"
39
+ CONSUMER_SECRET = "Your Consumer Secret"
40
+ HASH_TAG = "#sencha"
41
+ SEARCH_LIMIT = 50
42
+
43
+ TouchTweet::App.setRoot(File.expand_path(File.dirname(__FILE__)))
44
+ TouchTweet::App.run!
45
+
46
+ Put the your tweet app's consumer key and consumer secret on `TouchTweet::App::CONSUMER_KEY` and `TouchTweet::App::CONSUMER_SECRET`. `HASH_TAG` is used for search and post a tweet. `SEARCH_LIMIT` is also used to search a tweet.
47
+
48
+ That's all! After you have to do is use it. :)
49
+
50
+ $ ruby app.rb
51
+
52
+ [2014-05-17 16:21:29] INFO WEBrick 1.3.1
53
+ ...
54
+ [2014-05-17 16:21:29] INFO WEBrick::HTTPServer#start: pid=96175 port=4567
55
+
56
+ You can execute twitter login function with GET `/login`.
57
+
58
+ ![alt tag](https://raw.githubusercontent.com/kawanoshinobu/twitter_client_app/master/images/1.png)
59
+
60
+ ![alt tag](https://raw.githubusercontent.com/kawanoshinobu/twitter_client_app/master/images/2.png)
61
+
62
+ You can get tweets (it's a JSON format) from Twitter with GET `/tweets`.
63
+
64
+ ![alt tag](https://raw.githubusercontent.com/kawanoshinobu/twitter_client_app/master/images/3.png)
65
+
66
+ You can post a tweet with POST `/post`.
67
+
68
+ ![alt tag](https://raw.githubusercontent.com/kawanoshinobu/twitter_client_app/master/images/4.png)
69
+
70
+ For more information, please see the files of `example` directory.
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it ( https://github.com/[my-github-username]/twitter_client_app/fork )
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/example/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem 'twitter_client_app'
data/example/app.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'twitter_client_app'
2
+
3
+ # Define app config
4
+ CONSUMER_KEY = "Your Consumer key"
5
+ CONSUMER_SECRET = "Your Consumer Secret"
6
+ HASH_TAG = "#sencha"
7
+ SEARCH_LIMIT = 50
8
+
9
+ TwitterClientApp::App.setRoot(File.expand_path(File.dirname(__FILE__)))
10
+ TwitterClientApp::App.run!
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Twitter Client App</title>
5
+ </head>
6
+ <body>
7
+ <h2>Twitter Client App</h2>
8
+ <div>
9
+ <a href='/login'>Login</a>
10
+ </div>
11
+ <div>
12
+ <a href='/logout'>Logout</a>
13
+ </div>
14
+ <div>
15
+ <a href='/tweets'>Get Tweets</a>
16
+ </div>
17
+ <div>
18
+ <form action="/post" method="post">
19
+ <textarea name="text" rows="4" cols="40"></textarea>
20
+ <input type="submit" name="submit" value="Post Tweet" />
21
+ </form>
22
+ </div>
23
+ </body>
24
+ </html>
data/images/1.png ADDED
Binary file
data/images/2.png ADDED
Binary file
data/images/3.png ADDED
Binary file
data/images/4.png ADDED
Binary file
@@ -0,0 +1,3 @@
1
+ module TwitterClientApp
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,102 @@
1
+ require "twitter_client_app/version"
2
+
3
+ require 'sinatra'
4
+ require 'sinatra/json'
5
+ require 'sinatra/reloader'
6
+ require 'oauth'
7
+ require 'twitter'
8
+ require 'pry'
9
+
10
+ module TwitterClientApp
11
+
12
+ class App < Sinatra::Base
13
+ set :server, 'webrick'
14
+ enable :sessions
15
+
16
+ get '/' do
17
+ send_file File.join(settings.public_folder, 'index.html')
18
+ end
19
+
20
+ get '/connect' do
21
+ client = session[:access_token]
22
+ json connect: !client.nil?
23
+ end
24
+
25
+ get '/login' do
26
+ callback_url = "http://127.0.0.1:4567/callback"
27
+ request_token = oauth_consumer.get_request_token(:oauth_callback => callback_url)
28
+
29
+ session[:request_token] = request_token.token
30
+ session[:request_token_secret] = request_token.secret
31
+ redirect request_token.authorize_url
32
+ end
33
+
34
+ get '/callback' do
35
+ request_token = OAuth::RequestToken.new(oauth_consumer, session[:request_token], session[:request_token_secret])
36
+
37
+ access_token = nil
38
+ begin
39
+ access_token = request_token.get_access_token(
40
+ {},
41
+ oauth_token: params[:oauth_token],
42
+ oauth_verifier: params[:oauth_verifier])
43
+ rescue OAuth::Unauthorized => @exception
44
+ raise
45
+ end
46
+
47
+ # binding.pry
48
+
49
+ session[:access_token] = access_token.token
50
+ session[:access_token_secret] = access_token.secret
51
+
52
+ redirect '/';
53
+ end
54
+
55
+ get '/logout' do
56
+ session.clear
57
+ redirect '/';
58
+ end
59
+
60
+ get '/tweets' do
61
+ client = get_client(session[:access_token], session[:access_token_secret])
62
+
63
+ result = client.search(HASH_TAG).take(SEARCH_LIMIT)
64
+ data = result.map do |tweet|
65
+ {
66
+ id: tweet.id,
67
+ userName: tweet.user.name,
68
+ profile: tweet.user.profile_image_url.to_s,
69
+ text: tweet.text
70
+ }
71
+ end
72
+
73
+ data.to_json
74
+ end
75
+
76
+ post '/post' do
77
+ client = get_client(session[:access_token], session[:access_token_secret])
78
+ text = params['text']
79
+ client.update(text + ' ' + HASH_TAG)
80
+ json success: true
81
+ end
82
+
83
+ def self.setRoot(root_directory)
84
+ set :root, root_directory
85
+ end
86
+
87
+ def oauth_consumer
88
+ return OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => "https://api.twitter.com")
89
+ end
90
+
91
+ def get_client(access_token, access_token_secret)
92
+ return Twitter::REST::Client.new do |config|
93
+ config.consumer_key = CONSUMER_KEY
94
+ config.consumer_secret = CONSUMER_SECRET
95
+ config.access_token = access_token
96
+ config.access_token_secret = access_token_secret
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ 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_client_app/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "twitter_client_app"
8
+ spec.version = TwitterClientApp::VERSION
9
+ spec.authors = ["KAWANO Shinobu"]
10
+ spec.email = ["kawanoshinobu@gmail.com"]
11
+ spec.summary = "A simple Sinatra app which is integrated with Twitter Oauth login and some of its API."
12
+ spec.description = "This gem aims for Sencha MokuMoku Meetup 2nd (that be held in Japan at 2014/05/30)."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "sinatra"
22
+ spec.add_dependency "sinatra-contrib"
23
+ spec.add_dependency "oauth"
24
+ spec.add_dependency "twitter"
25
+ spec.add_dependency "pry"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.6"
28
+ spec.add_development_dependency "rake"
29
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitter_client_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - KAWANO Shinobu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra-contrib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: twitter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: This gem aims for Sencha MokuMoku Meetup 2nd (that be held in Japan at
112
+ 2014/05/30).
113
+ email:
114
+ - kawanoshinobu@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - example/Gemfile
125
+ - example/app.rb
126
+ - example/public/index.html
127
+ - images/1.png
128
+ - images/2.png
129
+ - images/3.png
130
+ - images/4.png
131
+ - lib/twitter_client_app.rb
132
+ - lib/twitter_client_app/version.rb
133
+ - twitter_client_app.gemspec
134
+ homepage: ''
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A simple Sinatra app which is integrated with Twitter Oauth login and some
158
+ of its API.
159
+ test_files: []