jumble 0.1.0

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: a4bb1934a5059f6033b2db4041805aac073a2949
4
+ data.tar.gz: 17a069ff3b29d62efa22112689860b9bffb9d8e1
5
+ SHA512:
6
+ metadata.gz: 4f2f13b494d4a666ae6ee3a5b59ed835204b8747bc9cee77efa663ec30b378a852514908953534e910ed82d6b044a69014c0a475a11230ccc80caa5459e6cac2
7
+ data.tar.gz: b429a7741d953519c16864c41cfe651de9a6a8a7fbc19a522c9d1f9763ea69ccb20bab7612c6e4b65291581214faedfe4bf2a8799be923508bbb90123caeac22
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrey Ognevsky
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
+ # Jumble
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jumble'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jumble
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,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jumble/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'jumble'
8
+ spec.version = Jumble::VERSION
9
+ spec.authors = ['Andrey Ognevsky']
10
+ spec.email = ['a.ognevsky@gmail.com']
11
+ spec.description = 'Enable clients pool for twitter'
12
+ spec.summary = 'Enable clients pool for twitter'
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 'rails', '~> 4.0.1'
23
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
24
+ spec.add_development_dependency 'rspec-rails', '~> 2.14.0'
25
+ spec.add_development_dependency 'sqlite3', '~> 1.3.8'
26
+
27
+ spec.add_runtime_dependency 'twitter'
28
+ end
@@ -0,0 +1,7 @@
1
+ Description:
2
+ Generates basic config file to get you up and running the Jumble gem
3
+
4
+ Examples:
5
+ rails generate jumble:install
6
+
7
+ This will generate the config file in your config/ directory.
@@ -0,0 +1,13 @@
1
+ module Jumble
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_config_file
8
+ copy_file 'jumble.yml', 'config/jumble.yml'
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ ---
2
+
3
+ - :consumer_key: ''
4
+ :consumer_secret: ''
5
+ :access_token: ''
6
+ :access_token_secret: ''
7
+
8
+ - :consumer_key: ''
9
+ :consumer_secret: ''
10
+ :access_token: ''
11
+ :access_token_secret: ''
@@ -0,0 +1,4 @@
1
+ require 'jumble/rest/error'
2
+ require 'jumble/rest/client'
3
+ require 'jumble/rest/connection'
4
+ require 'jumble/version'
@@ -0,0 +1,43 @@
1
+ require 'twitter'
2
+
3
+ module Jumble
4
+ module REST
5
+ class Client < BasicObject
6
+
7
+ private
8
+
9
+ def connection
10
+ @connection ||= connections.sample
11
+ end
12
+
13
+ def connections
14
+ @connections ||= config.map { |payload| Connection.new(payload) }
15
+ end
16
+
17
+ def config
18
+ @config ||= begin
19
+ file = ::File.open(::Rails.root.join('config', 'jumble.yml'))
20
+ ::YAML.load(file)
21
+ end
22
+ end
23
+
24
+ def method_missing(*args, &block)
25
+ connection.client.send(*args, &block)
26
+ rescue ::Twitter::Error::TooManyRequests => e
27
+ connection.reset(e.rate_limit.reset_at)
28
+
29
+ if connections.any?(&:alive?)
30
+ @connection = next_connection
31
+ retry
32
+ else
33
+ raise TooManyRequests.new(next_connection.reset_at)
34
+ end
35
+ end
36
+
37
+ def next_connection
38
+ connections.sort.first
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ module Jumble
2
+ module REST
3
+ class Connection
4
+ attr_reader :client
5
+ attr_accessor :reset_at
6
+
7
+ def initialize(payload)
8
+ @reset_at = Time.now
9
+ @client = Twitter::REST::Client.new(payload)
10
+ end
11
+
12
+ def <=>(other)
13
+ reset_at <=> other.reset_at
14
+ end
15
+
16
+ def alive?
17
+ reset_at < Time.now
18
+ end
19
+
20
+ def reset(reset_at)
21
+ self.reset_at = reset_at
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Jumble
2
+ module REST
3
+ class TooManyRequests < StandardError
4
+ attr_reader :reset_at
5
+
6
+ def initialize(reset_at = nil)
7
+ @reset_at = reset_at
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Jumble
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jumble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Ognevsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-09 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: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.8
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.8
83
+ - !ruby/object:Gem::Dependency
84
+ name: twitter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Enable clients pool for twitter
98
+ email:
99
+ - a.ognevsky@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - jumble.gemspec
110
+ - lib/generators/jumble/USAGE
111
+ - lib/generators/jumble/install_generator.rb
112
+ - lib/generators/jumble/templates/jumble.yml
113
+ - lib/jumble.rb
114
+ - lib/jumble/rest/client.rb
115
+ - lib/jumble/rest/connection.rb
116
+ - lib/jumble/rest/error.rb
117
+ - lib/jumble/version.rb
118
+ homepage: ''
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.1.9
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Enable clients pool for twitter
142
+ test_files: []
143
+ has_rdoc: