long_tweet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8da8eac7c6e4766455f458072981ef087d7e71d8
4
+ data.tar.gz: b7abbb0b254ea0d33fbf93cf2029f09e5b97ded9
5
+ SHA512:
6
+ metadata.gz: d3f7090682e001647e5cfb9b0973bc2da9fa779ffec5e7fbce292d3dfefd9765c0cddb9f4c69c4dc7857c5f9d11b8084b7a7056316d3451b3a5da259592fa413
7
+ data.tar.gz: 1bf6b918e18e2922eba3e35b9dc8a4e29c2c1470807f426134a127c4b56b764d817610a8128f68dc41452848ccb3c5815799b20a239d58b63366a1077db46be9
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .rbx
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in long_tweet.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Stuart Nelson
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.
@@ -0,0 +1,29 @@
1
+ # LongTweet
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'long_tweet'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install long_tweet
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #! usr/bin/env ruby
2
+
3
+ require 'long_tweet'
4
+
5
+ puts 'What would you like to tweet?'
6
+ tweet = gets.strip
7
+
8
+ LongTweet::Master.new(tweet, Twitter).post
@@ -0,0 +1,5 @@
1
+ #! usr/bin/env ruby
2
+
3
+ require 'long_tweet'
4
+
5
+ LongTweet::Setup.new.run
@@ -0,0 +1,37 @@
1
+ require "long_tweet/version"
2
+ require "long_tweet/splitter"
3
+ require "long_tweet/naive_splitter"
4
+ require "long_tweet/ideal_splitter"
5
+ require "long_tweet/tweet"
6
+ require "long_tweet/arranger"
7
+ require "long_tweet/config"
8
+ require "long_tweet/setup"
9
+ require 'twitter'
10
+
11
+ trap("INT") { puts "\n\nExiting.."; exit 1 }
12
+
13
+ module LongTweet
14
+ class Master
15
+ attr_reader :text, :tweets, :agent
16
+ def initialize text, agent
17
+ @text = text
18
+ @agent = agent
19
+ create_ordered_tweets
20
+ configure_agent
21
+ end
22
+
23
+ def configure_agent
24
+ Config.new(agent).configure
25
+ end
26
+
27
+ def create_ordered_tweets
28
+ tweets = Splitter.new(text).split
29
+ @tweets = Arranger.new(tweets).order
30
+ end
31
+
32
+ def post
33
+ tweets.each(&:post)
34
+ puts "Sending Tweet: #{text}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ module LongTweet
2
+ class Arranger
3
+ attr_reader :tweets
4
+ def initialize tweets
5
+ @tweets = tweets
6
+ end
7
+
8
+ def order
9
+ tweets.reverse
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ require "general_store"
2
+
3
+ module LongTweet
4
+ class Config
5
+ attr_reader :agent, :store
6
+ def initialize agent
7
+ @agent = agent
8
+ @store = GeneralStore.read('~/.long_tweet')
9
+ end
10
+
11
+ def configure
12
+ agent.configure do |config|
13
+ config.consumer_key = store.consumer_key
14
+ config.consumer_secret = store.consumer_secret
15
+ config.oauth_token = store.oauth_token
16
+ config.oauth_token_secret = store.oauth_token_secret
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module LongTweet
2
+ class IdealSplitter < Splitter
3
+ attr_reader :text
4
+ def initialize text
5
+ @text = text
6
+ end
7
+
8
+ def split
9
+ a = []
10
+ ary = text.split
11
+ tweet = ''
12
+ while ary.length > 0
13
+ while (tweet.length + ary.first.length) < 140
14
+ tweet << "#{ary.shift} "
15
+ break if ary.empty?
16
+ end
17
+ a << Tweet.new(tweet.strip)
18
+ tweet = ''
19
+ end
20
+ a
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module LongTweet
2
+ class NaiveSplitter < Splitter
3
+ attr_reader :text
4
+ def initialize text
5
+ @text = text
6
+ end
7
+
8
+ def split
9
+ a = []
10
+ i = 0
11
+ tweet_count.times do
12
+ a << Tweet.new(text.slice(i*140,140))
13
+ i += 1
14
+ end
15
+ a
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ require 'general_store'
2
+
3
+ module LongTweet
4
+ class Setup
5
+ def ask question
6
+ puts question
7
+ gets.strip
8
+ end
9
+
10
+ def run
11
+ @consumer_key = ask 'What is your consumer key?'
12
+ @consumer_secret = ask 'What is your consumer secret?'
13
+ @oauth_token = ask 'What is your oauth token?'
14
+ @oauth_token_secret = ask 'What is your oauth secret?'
15
+ set_credentials
16
+ puts 'All done!'
17
+ end
18
+
19
+ def set_credentials
20
+ GeneralStore.create '~/.long_tweet' do |gs|
21
+ gs.consumer_key = @consumer_key
22
+ gs.consumer_secret = @consumer_secret
23
+ gs.oauth_token = @oauth_token
24
+ gs.oauth_token_secret = @oauth_token_secret
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,27 @@
1
+ module LongTweet
2
+ class Splitter
3
+ attr_reader :text
4
+ def initialize text
5
+ @text = text
6
+ @splitter = set_splitter
7
+ end
8
+
9
+ def set_splitter
10
+ if text.split.any? {|e| e.length > 140 }
11
+ NaiveSplitter.new text
12
+ else
13
+ IdealSplitter.new text
14
+ end
15
+ end
16
+
17
+ def tweet_count
18
+ tweet_count = text.length/140
19
+ tweet_count += 1 if text.length.modulo(140) > 0
20
+ tweet_count
21
+ end
22
+
23
+ def split
24
+ @splitter.split
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'twitter'
2
+
3
+ module LongTweet
4
+ class Tweet
5
+ attr_reader :text, :agent
6
+
7
+ def initialize text, agent = Twitter
8
+ @text = text
9
+ @agent = agent
10
+ end
11
+
12
+ def post
13
+ agent.update(text)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module LongTweet
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'long_tweet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "long_tweet"
8
+ spec.version = LongTweet::VERSION
9
+ spec.authors = ["Stuart Nelson"]
10
+ spec.email = ["stuartnelson3@gmail.com"]
11
+ spec.description = %q{Create a long tweet and have it posted for your followers in top-to-bottom order}
12
+ spec.summary = %q{Tweet longer tweets in order}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_dependency "twitter", "~> 4.8"
26
+ spec.add_dependency "general_store"
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe LongTweet::Arranger do
4
+ subject { LongTweet::Arranger }
5
+
6
+ it 'inits with an array' do
7
+ expect { subject.new [] }.to_not raise_error
8
+ end
9
+
10
+ context 'sorting tweets' do
11
+ it 'sorts in reverse by default' do
12
+ tweets = [1,2,3,4,5]
13
+ expect(subject.new(tweets).order).to eq(tweets.reverse)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe LongTweet::Config do
4
+ subject { LongTweet::Config }
5
+
6
+ it 'takes an agent as its init argument' do
7
+ expect { subject.new 'some agent' }.to_not raise_error
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe LongTweet::IdealSplitter do
4
+ subject { LongTweet::IdealSplitter.new words }
5
+ let(:lorem) { %w{lorenm ipsummm dolor sit ament} }
6
+ let(:words) { (lorem*8).join(' ') }
7
+ let(:first_tweet) { subject.split.first }
8
+
9
+ it 'only have full words in tweets' do
10
+ last_word = first_tweet.text.split.last
11
+ expect(lorem.include? last_word).to be_true
12
+ end
13
+
14
+ it 'doesnt exceed 140 characters when creating a tweet' do
15
+ splitter = LongTweet::IdealSplitter.new('a '*140)
16
+ text = splitter.split.first.text
17
+ expect(text.length < 141).to be_true
18
+ end
19
+
20
+ it 'returns a tweet when there are < 140 characeters' do
21
+ result = LongTweet::IdealSplitter.new('derp').split
22
+ expect(result.first.text).to eq('derp')
23
+ end
24
+
25
+ it 'returns a postable object' do
26
+ expect(first_tweet).to respond_to :post
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe LongTweet::Master do
4
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe LongTweet::NaiveSplitter do
4
+ subject { LongTweet::NaiveSplitter }
5
+ let(:text) { 'a'*140*2 }
6
+
7
+ it 'should create a tweet for every 140 characters' do
8
+ tweets = subject.new(text).split
9
+ expect(tweets.first.text.length).to eq 140
10
+ end
11
+
12
+ it 'should have the right length for the last tweet' do
13
+ tweets = subject.new(text + 'a'*20).split
14
+ expect(tweets.last.text.length).to eq 20
15
+ end
16
+
17
+ it 'returns a postable object' do
18
+ expect(subject.new(text).split.first).to respond_to :post
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe LongTweet::Splitter do
4
+ subject { LongTweet::Splitter.new text }
5
+ let(:text) { 'a'*140*3 }
6
+
7
+ it 'should know its tweet count' do
8
+ expect(subject.tweet_count).to eq 3
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe LongTweet::Tweet do
4
+ subject { LongTweet::Tweet.new text }
5
+ let(:text) { 'some tweet' }
6
+
7
+ it 'should respond to text' do
8
+ expect(subject).to respond_to :text
9
+ end
10
+
11
+ it 'should return its text' do
12
+ expect(subject.text).to eq('some tweet')
13
+ end
14
+
15
+ it 'should receive the send message' do
16
+ twitter = double 'twitter'
17
+ twitter.should_receive(:update).with(text)
18
+ LongTweet::Tweet.new(text, twitter).post
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'long_tweet'
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: long_tweet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stuart Nelson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: '4.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: general_store
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
+ description: Create a long tweet and have it posted for your followers in top-to-bottom
84
+ order
85
+ email:
86
+ - stuartnelson3@gmail.com
87
+ executables:
88
+ - long_tweet
89
+ - long_tweet_setup
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - .gitignore
94
+ - .rspec
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/long_tweet
100
+ - bin/long_tweet_setup
101
+ - lib/long_tweet.rb
102
+ - lib/long_tweet/arranger.rb
103
+ - lib/long_tweet/config.rb
104
+ - lib/long_tweet/ideal_splitter.rb
105
+ - lib/long_tweet/naive_splitter.rb
106
+ - lib/long_tweet/setup.rb
107
+ - lib/long_tweet/splitter.rb
108
+ - lib/long_tweet/tweet.rb
109
+ - lib/long_tweet/version.rb
110
+ - long_tweet.gemspec
111
+ - spec/long_tweet/arranger_spec.rb
112
+ - spec/long_tweet/config_spec.rb
113
+ - spec/long_tweet/ideal_splitter_spec.rb
114
+ - spec/long_tweet/long_tweet_spec.rb
115
+ - spec/long_tweet/naive_splitter_spec.rb
116
+ - spec/long_tweet/splitter_spec.rb
117
+ - spec/long_tweet/tweet_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: ''
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.0.7
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Tweet longer tweets in order
143
+ test_files:
144
+ - spec/long_tweet/arranger_spec.rb
145
+ - spec/long_tweet/config_spec.rb
146
+ - spec/long_tweet/ideal_splitter_spec.rb
147
+ - spec/long_tweet/long_tweet_spec.rb
148
+ - spec/long_tweet/naive_splitter_spec.rb
149
+ - spec/long_tweet/splitter_spec.rb
150
+ - spec/long_tweet/tweet_spec.rb
151
+ - spec/spec_helper.rb