Skip to content
This repository has been archived by the owner on Oct 26, 2020. It is now read-only.

Commit

Permalink
Continuing move to pass twitter keys in, in order to make more gem fr…
Browse files Browse the repository at this point in the history
…iendly.
  • Loading branch information
ryanwi committed Sep 13, 2013
1 parent 712bdc2 commit 8d226fe
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
@@ -1 +1 @@
ruby-2.0.0-p247
2.0
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -5,7 +5,7 @@ GEM
faraday (0.8.8)
multipart-post (~> 1.2.0)
mini_portile (0.5.1)
multi_json (1.7.9)
multi_json (1.8.0)
multipart-post (1.2.0)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
Expand All @@ -14,7 +14,7 @@ GEM
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.5)
rspec-expectations (2.14.1)
rspec-expectations (2.14.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.3)
simple_oauth (0.2.0)
Expand Down
19 changes: 16 additions & 3 deletions README.md
Expand Up @@ -29,21 +29,34 @@ With a command line

To export a Twitter List, use a combination of username and list name
```ruby
twexport = Twexport::TwitterList.new(:screen_name => "twitter", :list_slug => "team")
twexport = Twexport::TwitterList.new(:screen_name => "twitter", :list_slug => "team",
:consumer_key => "",
:consumer_secret => "",
:access_token => "",
:access_token_secret => "")
twexport.save('team.csv')
```

or use a list id
```ruby
twexport = Twexport::TwitterList.new(:list_id => 2031945)
twexport = Twexport::TwitterList.new(:list_id => 2031945,
:consumer_key => "",
:consumer_secret => "",
:access_token => "",
:access_token_secret => ""))
twexport.save('team.csv')
```

To export information for users listed in a web page
```ruby
twexport = Twexport::WebPage.new("http://techcrunch.com/about/")
twexport = Twexport::WebPage.new(:url => "http://techcrunch.com/about/",
:consumer_key => "",
:consumer_secret => "",
:access_token => "",
:access_token_secret => "")
twexport.save('tcwriters.csv')
```


## Other libraries of interest
[t - A command-line power tool for Twitter](http://sferik.github.com/t/)
10 changes: 5 additions & 5 deletions lib/twexport/exporter.rb
Expand Up @@ -7,13 +7,13 @@ class Exporter
attr_accessor :client
attr_accessor :users

def initialize(config = {})
def initialize(options = {})
# configure twitter client
@client = Twitter::Client.new(
:consumer_key => config[:consumer_key],
:consumer_secret => config[:consumer_secret],
:oauth_token => config[:oauth_token],
:oauth_token_secret => config[:oauth_token_secret]
:consumer_key => options[:consumer_key],
:consumer_secret => options[:consumer_secret],
:oauth_token => options[:access_token],
:oauth_token_secret => options[:access_token_secret]
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/twexport/twitter_list.rb
Expand Up @@ -9,7 +9,7 @@ def initialize(options = {})
@list_id = options[:list_id]
@screen_name = options[:screen_name]
@list_slug = options[:list_slug]
super()
super(options)
end

# Execute the Twitter List API call and save the result
Expand Down
6 changes: 3 additions & 3 deletions lib/twexport/web_page.rb
Expand Up @@ -6,9 +6,9 @@ module Twexport
# Exporter that scrapes a web page for Twitter usernames to lookup on Twitter
class WebPage < Exporter

def initialize(url)
@url = url
super()
def initialize(options = {})
@url = options[:url]
super(options)
end

# Execute the export and save the result
Expand Down
30 changes: 12 additions & 18 deletions spec/twexport/exporter_spec.rb
@@ -1,28 +1,22 @@
require_relative '../spec_helper'

describe Twexport::Exporter do
it "initializes with config" do
twexport = Twexport::Exporter.new(:consumer_key => '',
:consumer_secret => '',
:oauth_token => '',
:oauth_token_secret => '')
before :each do
@twexport = Twexport::Exporter.new(
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
:access_token => ACCESS_TOKEN,
:access_token_secret => ACCESS_TOKEN_SECRET)
end

it "initializes with twitter keys" do
end

it "looks up single user in Twitter API" do
twexport = Twexport::Exporter.new(:consumer_key => '',
:consumer_secret => '',
:oauth_token => '',
:oauth_token_secret => '')
users = twexport.lookup_users ['ryanwi']
# puts users.inspect
users = @twexport.lookup_users ['ryanwi']
end

it "looks up users in Twitter API" do
twexport = Twexport::Exporter.new(:consumer_key => '',
:consumer_secret => '',
:oauth_token => '',
:oauth_token_secret => '')
users = twexport.lookup_users ['corybooker','lolojones','xeni']
# puts users.inspect
it "looks up multiple users in Twitter API" do
users = @twexport.lookup_users ['corybooker','lolojones','xeni']
end
end
20 changes: 14 additions & 6 deletions spec/twexport/twitter_list_spec.rb
Expand Up @@ -2,12 +2,20 @@

describe Twexport::TwitterList do
it "requests list by screen name and slug" do
twexport = Twexport::TwitterList.new(:screen_name => "rails", :list_slug => "core")
twexport.save("rails_core.csv")
twexport = Twexport::TwitterList.new(:screen_name => "rails", :list_slug => "core",
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
:access_token => ACCESS_TOKEN,
:access_token_secret => ACCESS_TOKEN_SECRET)
twexport.save("rails_core_slug.csv")
end

# it "requests list by id" do
# twexport = Twexport::TwitterList(:list_id => 574)
# twexport.save("twitter_team.csv")
# end
it "requests list by id" do
twexport = Twexport::TwitterList.new(:list_id => 4447,
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
:access_token => ACCESS_TOKEN,
:access_token_secret => ACCESS_TOKEN_SECRET)
twexport.save("rails_core_id.csv")
end
end
12 changes: 10 additions & 2 deletions spec/twexport/web_page_spec.rb
Expand Up @@ -2,14 +2,22 @@

describe Twexport::WebPage do
it "finds 1 twitter username to extract" do
twexport = Twexport::WebPage.new 'http://www.ryan-williams.net'
twexport = Twexport::WebPage.new(:url => "http://www.ryan-williams.net",
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
:access_token => ACCESS_TOKEN,
:access_token_secret => ACCESS_TOKEN_SECRET)
names = twexport.send(:extract_names)
names.count.should == 1
names.first.should == 'ryanwi'
end

it "saves list with 1 member extracted from web page" do
twexport = Twexport::WebPage.new 'http://www.ryan-williams.net'
twexport = Twexport::WebPage.new(:url => "http://www.ryan-williams.net",
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET,
:access_token => ACCESS_TOKEN,
:access_token_secret => ACCESS_TOKEN_SECRET)
twexport.save("webpage_export.csv")
end

Expand Down
4 changes: 2 additions & 2 deletions twexport.gemspec
@@ -1,8 +1,8 @@
Gem::Specification.new do |s|
s.name = 'twexport'
s.version = '0.0.1'
s.date = '2013-09-04'
s.summary = 'Bulk export Twitter profile information to CSV'
s.date = '2013-09-12'
s.summary = 'Export Twitter profile information to CSV'
s.description = 'Twexport enables quick access to bulk Twitter profile information to be used for your analysis needs.
Given a list of twitter usernames, a twitter list, or a web page with one or many links to twitter profiles,
Twexport can gather profile information from the Twitter API and export into a CSV file.'
Expand Down

0 comments on commit 8d226fe

Please sign in to comment.