my_timeline-twitter 0.0.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
+ SHA1:
3
+ metadata.gz: ad17b41b2a3e105007ae974c2f2573b5b8009c71
4
+ data.tar.gz: 3019fddbdbe80d025e3ef54f146b300305d07c97
5
+ SHA512:
6
+ metadata.gz: 24d07a1d370811a87d522fbcc12641fd98957299d018d2b9b5343f0dc546a4e2b5198127631f0bed907a4d1b489e702044aaf764f044c2c784d0170b55ff4363
7
+ data.tar.gz: 7f60c90e98a7cae6b567c3efc3525e16f642d99ccb2f00ddbe2b97c5c67f9df3e2ecc75fdd9f0a385bab43baf2f9ee45aafce5ccd7007d26c639440bf9072533
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ .ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Justin Aiken
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,50 @@
1
+ [![Code Climate](https://codeclimate.com/github/JustinAiken/my_timeline-twitter.png)](https://codeclimate.com/github/JustinAiken/my_timeline-twitter)
2
+
3
+ # My Timeline - Twitter Plugin
4
+ #### Twitter Integration with My Timeline
5
+
6
+ ### Requirements:
7
+ - [My Timeline](https://github.com/JustinAiken/my_timeline)
8
+ - [Twitter gem](https://github.com/sferik/twitter)
9
+
10
+ ### Usage:
11
+
12
+ 1. Add this gem to your Gemfile:
13
+ `gem 'my_timeline-twitter'` and `bundle install`
14
+ 2. Edit `config/initializers/my_timeline.rb` to include your API keys:
15
+
16
+ ```ruby
17
+ MyTimeline.setup do |config|
18
+ ...
19
+ end
20
+
21
+ MyTimeline::Twitter.setup do |config|
22
+ config.client_id = "lotsofrandomhexchars"
23
+ config.client_secret = "lotsofrandomhexchars"
24
+ config.access_token = "lotsofrandomhexchars"
25
+ config.access_token_secret = "lotsofrandomhexchars"
26
+ end
27
+ ```
28
+
29
+ ## Credits
30
+
31
+ Original author: [Justin Aiken](https://github.com/JustinAiken)
32
+
33
+ ## Links
34
+
35
+ * [Source](https://github.com/JustinAiken/my_timeline-twitter)
36
+ * [Bug Tracker](https://github.com/JustinAiken/my_timeline-twitter/issues)
37
+ * [Rubygem](https://rubygems.org/gems/my_timeline-twitter)
38
+
39
+ ## Note on Patches/Pull Requests
40
+
41
+ * Fork the project.
42
+ * Make your feature addition or bug fix.
43
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
44
+ * Commit, do not mess with rakefile, version, or history.
45
+ * If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
46
+ * Send me a pull request. Bonus points for topic branches.
47
+
48
+ ## Copyright
49
+
50
+ Copyright (c) 2013 Justin Aiken Inc. MIT license (see LICENSE for details).
@@ -0,0 +1,15 @@
1
+ module MyTimeline
2
+ class TwitterController < ApplicationController
3
+
4
+ def new
5
+ @user.settings(:twitter).user_name = params[:user_name]
6
+ @user.save!
7
+ redirect_to control_panel_path, notice: "Twitter added!"
8
+ end
9
+
10
+ def scrape
11
+ scrapey = MyTimeline::Twitter::TweetScraper.new(@user).scrape
12
+ redirect_to :back, notice: "Added #{scrapey} tweets."
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module MyTimeline
2
+ module Twitter
3
+ class Tweet < ActiveRecord::Base
4
+ self.table_name = :my_timeline_twitter_tweets
5
+ belongs_to :event #,dependant: :destroy
6
+
7
+ attr_protected
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,53 @@
1
+ module MyTimeline
2
+ module Twitter
3
+ class TweetBuilder
4
+
5
+ attr_reader :user, :tweet_hash
6
+
7
+ def initialize(user)
8
+ @user = user
9
+ end
10
+
11
+ def build_tweet(tweet_hash)
12
+ @tweet_hash = tweet_hash
13
+ return false if already_exists_in_db?
14
+
15
+ event = MyTimeline::Event.create(
16
+ happened_on: tweet_hash.created_at,
17
+ original_id: tweet_hash.id,
18
+ external_link: "http://twitter.com/#{user.settings(:twitter).user_name}/status/#{tweet_hash.id}",
19
+ icon_name: "tweetweet_hash.png",
20
+ importance: 5,
21
+ public: 1,
22
+ description: linkup_mentions_and_hashtags
23
+ )
24
+
25
+ tweet = MyTimeline::Twitter::Tweet.new(
26
+ happened_on: tweet_hash.created_at,
27
+ uri: tweet_hash.id,
28
+ post: tweet_hash.text
29
+ )
30
+
31
+ event.linkable = tweet
32
+ event.user = user if MyTimeline.user_class
33
+ event.save
34
+
35
+ tweet.event = event
36
+ tweet.save
37
+ end
38
+
39
+ private
40
+
41
+ def already_exists_in_db?
42
+ MyTimeline::Twitter::Tweet.find_by_uri tweet_hash.id
43
+ end
44
+
45
+ def linkup_mentions_and_hashtags
46
+ text = tweet_hash.text.dup
47
+ text.gsub!(/@([\w]+)(\W)?/, '<a href="http://twitter.com/\1">@\1</a>\2')
48
+ text.gsub(/#([\w]+)(\W)?/, '<a href="http://twitter.com/search?q=%23\1">#\1</a>\2')
49
+ %Q{"#{text}"}
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'tweet_builder'
2
+ require 'twitter'
3
+
4
+ module MyTimeline
5
+ module Twitter
6
+ class TweetScraper
7
+
8
+ attr_accessor :user, :tweets
9
+
10
+ def initialize(user)
11
+ @user = user
12
+ end
13
+
14
+ def scrape
15
+ load_tweets
16
+ @count = 0
17
+
18
+ tweets.each do |tweet_hash|
19
+ @count = @count + 1 if builder.build_tweet(tweet_hash)
20
+ end
21
+
22
+ @count
23
+ end
24
+
25
+ def load_tweets
26
+ @tweets = twitter.user_timeline(@user.settings(:twitter).user_name, count: 200)
27
+ end
28
+
29
+ def builder
30
+ @builder ||= MyTimeline::Twitter::TweetBuilder.new(user)
31
+ end
32
+
33
+ def twitter
34
+ @twitter ||= ::Twitter::REST::Client.new do |config|
35
+ config.consumer_key = MyTimeline::Twitter.consumer_key
36
+ config.consumer_secret = MyTimeline::Twitter.consumer_secret
37
+ config.access_token = MyTimeline::Twitter.access_token
38
+ config.access_token_secret = MyTimeline::Twitter.access_token_secret
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ <h3> Twitter Settings </h3>
2
+ <% if @user.settings(:twitter).user_name %>
3
+ <%= button_to "Scrape tweets from #{@user.settings(:twitter).user_name}!", twitter_scrape_path, method: :get, class: "btn btn-primary" %>
4
+ <% else %>
5
+ <%= form_tag new_twitter_path, method: :post do %>
6
+ <%= label_tag :user_name %>
7
+ <%= text_field_tag :user_name %>
8
+ <br>
9
+ <%= submit_tag "Save username", class: "btn btn-primary" %>
10
+ <% end %>
11
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ MyTimeline::Engine.routes.draw do
2
+ match 'twitter/scrape' => 'twitter#scrape', as: "twitter_scrape"
3
+ post 'twitter/new' => 'twitter#new', as: "new_twitter"
4
+ resources :twitter
5
+ end
@@ -0,0 +1,13 @@
1
+ class CreateTweets < ActiveRecord::Migration
2
+ def change
3
+ create_table :my_timeline_twitter_tweets do |t|
4
+ t.datetime :happened_on
5
+
6
+ t.text :uri
7
+ t.text :post
8
+
9
+ t.references :event
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module MyTimeline
2
+ module Twitter
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace MyTimeline::Twitter
5
+
6
+ config.autoload_paths << File.expand_path("../../../app/classes/**", __FILE__)
7
+ config.autoload_paths << File.expand_path("../../../app/scrapers/**", __FILE__)
8
+
9
+ config.generators do |g|
10
+ g.test_framework :rspec, fixture: false
11
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
12
+ g.assets false
13
+ g.helper false
14
+ end
15
+
16
+ config.after_initialize do |app|
17
+ MyTimeline.config_object.key :twitter, defaults: {user_token: nil}
18
+ MyTimeline.register_plugin :twitter
19
+ end
20
+
21
+ rake_tasks do
22
+ load File::expand_path "railties/twitter_tasks.rake", File.dirname(__FILE__)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ namespace "my_timeline-twitter" do
2
+ namespace :install do
3
+ desc "Copy migrations from my_timeline-twitter to application"
4
+ task :migrations do
5
+ timestamp = Time.now.strftime("%Y%m%d%H%M%S")
6
+
7
+ source = File.expand_path "../../../../db/migrate/20131107025006_create_tweets.rb", File.dirname(__FILE__)
8
+ dest = File.expand_path "db/migrate/#{timestamp}_create_tweets.my_timeline.rb"
9
+ puts "cp #{source} #{dest}"
10
+ `cp #{source} #{dest}`
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module MyTimeline
2
+ module Twitter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'twitter'
2
+
3
+ require "my_timeline"
4
+ require "my_timeline/twitter/engine"
5
+
6
+ module MyTimeline
7
+ module Twitter
8
+
9
+ mattr_accessor :consumer_key, :consumer_secret, :access_token, :access_token_secret
10
+
11
+ def self.setup
12
+ yield self
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "my_timeline/twitter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "my_timeline-twitter"
7
+ s.version = MyTimeline::Twitter::VERSION
8
+ s.authors = ["Justin Aiken"]
9
+ s.email = ["60tonangel@gmail.com"]
10
+ s.homepage = "https://www.github.com/JustinAiken/my_timeline-twitter"
11
+ s.summary = "Twitter plugin for MyTimeline"
12
+ s.description = "Twitter plugin for MyTimeline"
13
+ s.license = 'MIT'
14
+ s.files = `git ls-files`.split("\n")
15
+
16
+ s.add_runtime_dependency "my_timeline"
17
+ s.add_runtime_dependency "twitter", ['>= 5.0', '< 6.0']
18
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my_timeline-twitter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Aiken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: my_timeline
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: twitter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '6.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '5.0'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '6.0'
47
+ description: Twitter plugin for MyTimeline
48
+ email:
49
+ - 60tonangel@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.markdown
58
+ - app/assets/images/my_timeline/icons/tweetweet_hash.png
59
+ - app/assets/images/my_timeline/icons/twitter.png
60
+ - app/controllers/my_timeline/twitter_controller.rb
61
+ - app/models/my_timeline/twitter/tweet.rb
62
+ - app/scrapers/my_timeline/twitter/tweet_builder.rb
63
+ - app/scrapers/my_timeline/twitter/tweet_scraper.rb
64
+ - app/views/my_timeline/twitter/_control_panel.html.erb
65
+ - config/routes.rb
66
+ - db/migrate/20131107025006_create_tweets.rb
67
+ - lib/my_timeline-twitter.rb
68
+ - lib/my_timeline/twitter/engine.rb
69
+ - lib/my_timeline/twitter/railties/twitter_tasks.rake
70
+ - lib/my_timeline/twitter/version.rb
71
+ - my_timeline-twitter.gemspec
72
+ homepage: https://www.github.com/JustinAiken/my_timeline-twitter
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Twitter plugin for MyTimeline
96
+ test_files: []