statement 1.2 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,6 +30,14 @@ $ gem install statement
30
30
 
31
31
  Statement provides access to press releases, Facebook status updates and tweets from members of Congress. Most congressional offices have RSS feeds but some require HTML scraping.
32
32
 
33
+ To configure Statement to pull from the Twitter and Facebook APIs, you can pass in configuration values via a hash or a `config.yml` file:
34
+
35
+ ```ruby
36
+ require 'rubygems'
37
+ require 'statement'
38
+ Statement.configure(:oauth_token => token, :oauth_token_secret => secret, ...) # option 1
39
+ Statement.configure_with("config.yml") # option 2
40
+ ```
33
41
 
34
42
  ### Press Releases
35
43
 
@@ -1,5 +1,4 @@
1
1
  require 'twitter'
2
- require 'yaml'
3
2
 
4
3
  module Statement
5
4
  class Tweets
@@ -23,7 +22,11 @@ module Statement
23
22
 
24
23
  # batch lookup of users, 100 at a time
25
24
  def users(member_ids)
26
- client.users(member_ids)
25
+ results = []
26
+ member_ids.each_slice(100) do |batch|
27
+ results << client.users(batch)
28
+ end
29
+ results.flatten
27
30
  end
28
31
 
29
32
  # fetches latest 100 tweets from a list (derekwillis twitter acct has a public congress list)
@@ -1,3 +1,3 @@
1
1
  module Statement
2
- VERSION = "1.2"
2
+ VERSION = "1.3"
3
3
  end
data/lib/statement.rb CHANGED
@@ -4,7 +4,41 @@ require "statement/scraper"
4
4
  require "statement/utils"
5
5
  require "statement/facebook"
6
6
  require "statement/tweets"
7
+ require "yaml"
7
8
 
8
9
  module Statement
9
10
  extend Utils
11
+ @config = {
12
+ :app_id => nil,
13
+ :app_secret => nil,
14
+ :nyt_congress_api_key => nil,
15
+ :consumer_key => nil,
16
+ :consumer_secret => nil,
17
+ :oauth_token => nil,
18
+ :oauth_token_secret => nil
19
+ }
20
+
21
+ @valid_config_keys = @config.keys
22
+
23
+ # Configure through hash
24
+ def self.configure(opts = {})
25
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
26
+ end
27
+
28
+ # Configure through yaml file
29
+ def self.configure_with(path_to_yaml_file)
30
+ begin
31
+ config = YAML::load(IO.read(path_to_yaml_file))
32
+ rescue Errno::ENOENT
33
+ log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
34
+ rescue Psych::SyntaxError
35
+ log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
36
+ end
37
+
38
+ configure(config)
39
+ end
40
+
41
+ def self.config
42
+ @config
43
+ end
10
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statement
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-31 00:00:00.000000000 Z
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -214,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  segments:
216
216
  - 0
217
- hash: 513920917302805620
217
+ hash: -144207164694068116
218
218
  required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  none: false
220
220
  requirements:
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  version: '0'
224
224
  segments:
225
225
  - 0
226
- hash: 513920917302805620
226
+ hash: -144207164694068116
227
227
  requirements: []
228
228
  rubyforge_project:
229
229
  rubygems_version: 1.8.25