twitter-vine 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +8 -1
- data/lib/twitter-vine/client.rb +32 -6
- data/lib/twitter-vine/version.rb +1 -1
- data/lib/twitter-vine.rb +4 -28
- data/spec/spec_helper.rb +16 -1
- data/spec/twitter-vine_spec.rb +26 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmE5ZDI1OGM2Nzc5MmQ3NjQ0YjViZjk0NGUxOTIxYzgyZmI2ZjU0ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTI3OWQ2MGY5Nzk5NWRhNmQ0MmQzMjBmMGM1MmRhZmU1NzBmMTI1OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTYyY2I3NjA0MDRiZDcyMTlhYmU0N2MxNGI1ODUxOGNkZjUxZTI2YjFlMDhm
|
10
|
+
MTY5YWNhYTU4OTBmZWZkM2Q1N2QyM2FlMGYxODBkODIyMmIzMTY3YThhYjhi
|
11
|
+
OTMwMDhkOWEzMzc1M2E1YzEyMmZhNzRkNmM3ZmRmZWIzNGE2YzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGZiZmIzZGY0YjllNzE4ZDYwZjJlMDgxZGVmYWY4NWU4NjJlZGI5MzMxODll
|
14
|
+
YjljMjU5OWRlMzZiMTU1Y2JmNWY5YTljYmY3YjJmYjYzODBjNmExYmNkMGM1
|
15
|
+
YzBmM2FjNDE3NzU1YTA3ZWVmZmYxZmRjOTA1MWZmZDgyNTRlODg=
|
data/README.md
CHANGED
@@ -14,7 +14,13 @@ A ruby based API to get information about Vines and allow searching.
|
|
14
14
|
## Usage
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
|
17
|
+
# Simplest use case - give the link of a Vine
|
18
|
+
parts = TwitterVine.parse("https://vine.co/v/b2BPEL0Orbm")
|
19
|
+
|
20
|
+
```
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
TwitterVine::Client.setup do |config|
|
18
24
|
config.api_key = "YOUR_API_KEY"
|
19
25
|
config.api_secret = "YOUR_API_SECRET"
|
20
26
|
config.oauth_token = "YOUR_OAUTH_TOKEN"
|
@@ -25,3 +31,4 @@ end
|
|
25
31
|
```ruby
|
26
32
|
vines = TwitterVine::Client.search("Prank")
|
27
33
|
```
|
34
|
+
|
data/lib/twitter-vine/client.rb
CHANGED
@@ -2,6 +2,23 @@ require 'open-uri'
|
|
2
2
|
|
3
3
|
module TwitterVine
|
4
4
|
module Client
|
5
|
+
def self.api_key; @@api_key; end
|
6
|
+
def self.api_key=(val); @@api_key=val; end
|
7
|
+
|
8
|
+
def self.api_secret; @@api_secret; end
|
9
|
+
def self.api_secret=(val); @@api_secret=val; end
|
10
|
+
|
11
|
+
def self.oauth_token; @@oauth_token; end
|
12
|
+
def self.oauth_token=(val); @@oauth_token=val; end
|
13
|
+
|
14
|
+
def self.oauth_secret; @@oauth_secret; end
|
15
|
+
def self.oauth_secret=(val); @@oauth_secret=val; end
|
16
|
+
|
17
|
+
|
18
|
+
# Call setup to set global defaults for api_key, api_secret, oauth_token and oauth_secret
|
19
|
+
def self.setup
|
20
|
+
yield self
|
21
|
+
end
|
5
22
|
|
6
23
|
#
|
7
24
|
# OPTIONS:
|
@@ -15,10 +32,10 @@ module TwitterVine
|
|
15
32
|
def self.search(q, opts={})
|
16
33
|
# Always use a new client for Thread safety - is this necessary?
|
17
34
|
tc = ::Twitter::REST::Client.new do |config|
|
18
|
-
config.consumer_key = opts.delete(:api_key) ||
|
19
|
-
config.consumer_secret = opts.delete(:api_secret) ||
|
20
|
-
config.access_token = opts.delete(:oauth_token) ||
|
21
|
-
config.access_token_secret = opts.delete(:oauth_secret) ||
|
35
|
+
config.consumer_key = opts.delete(:api_key) || api_key
|
36
|
+
config.consumer_secret = opts.delete(:api_secret) || api_secret
|
37
|
+
config.access_token = opts.delete(:oauth_token) || oauth_token
|
38
|
+
config.access_token_secret = opts.delete(:oauth_secret) || oauth_secret
|
22
39
|
end
|
23
40
|
opts[:include_entities] = true
|
24
41
|
opts[:lang] ||= "en"
|
@@ -28,12 +45,11 @@ module TwitterVine
|
|
28
45
|
_normalize(tc.search(vine_criteria, opts))
|
29
46
|
end
|
30
47
|
|
31
|
-
|
32
48
|
private
|
33
49
|
# Does the processing inplace...
|
34
50
|
def self._normalize(results)
|
35
51
|
results.entries.map do |r|
|
36
|
-
vine_map =
|
52
|
+
vine_map = build_vine_map(r)
|
37
53
|
{
|
38
54
|
time: r.created_at,
|
39
55
|
id: r.id,
|
@@ -50,6 +66,16 @@ module TwitterVine
|
|
50
66
|
end.compact
|
51
67
|
end
|
52
68
|
|
69
|
+
def self.build_vine_map(twitter_result)
|
70
|
+
vine_url = twitter_result.urls.map do |u|
|
71
|
+
if u[:display_url] =~ /vine\.co\/v/
|
72
|
+
u[:expanded_url].to_s
|
73
|
+
end
|
74
|
+
end.compact.first
|
75
|
+
TwitterVine.parse(vine_url)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
53
79
|
end
|
54
80
|
end
|
55
81
|
|
data/lib/twitter-vine/version.rb
CHANGED
data/lib/twitter-vine.rb
CHANGED
@@ -3,46 +3,22 @@ require 'twitter'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
|
5
5
|
module TwitterVine
|
6
|
-
|
6
|
+
DEBUG = false
|
7
7
|
|
8
|
-
|
9
|
-
def self.api_key=(val); @@api_key=val; end
|
10
|
-
|
11
|
-
def self.api_secret; @@api_secret; end
|
12
|
-
def self.api_secret=(val); @@api_secret=val; end
|
13
|
-
|
14
|
-
def self.oauth_token; @@oauth_token; end
|
15
|
-
def self.oauth_token=(val); @@oauth_token=val; end
|
16
|
-
|
17
|
-
def self.oauth_secret; @@oauth_secret; end
|
18
|
-
def self.oauth_secret=(val); @@oauth_secret=val; end
|
19
|
-
|
20
|
-
|
21
|
-
# Call setup to set global defaults
|
22
|
-
def self.setup
|
23
|
-
yield self
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.build_vine_map(twitter_result)
|
27
|
-
vine_url = twitter_result.urls.map do |u|
|
28
|
-
if u[:display_url] =~ /vine\.co\/v/
|
29
|
-
u[:expanded_url].to_s
|
30
|
-
end
|
31
|
-
end.compact.first
|
8
|
+
def self.parse(vine_url)
|
32
9
|
vine_url.gsub!("http://", "https://")
|
10
|
+
vine_url.gsub!("/embed/simple", "")
|
33
11
|
puts "Got vine_url [#{vine_url}]" if DEBUG
|
34
12
|
doc = Nokogiri::HTML(open(vine_url))
|
35
13
|
{
|
36
14
|
vine_id: vine_url.match(/.*\/(.*)/)[1],
|
37
15
|
vine_url: vine_url,
|
16
|
+
vine_thumbnail: doc.xpath("//meta[@property='og:image']").first[:content],
|
38
17
|
vine_author_thumbnail: doc.css(".avatar-container img").first[:src],
|
39
18
|
vine_author: doc.css("p.username").text,
|
40
19
|
vine_description: doc.css("p.description").text.gsub(/\s+/," ").strip,
|
41
20
|
vine_src: doc.css("video source").first[:src],
|
42
21
|
vine_type: doc.css("video source").first[:type]
|
43
22
|
}
|
44
|
-
|
45
23
|
end
|
46
24
|
end
|
47
|
-
|
48
|
-
require 'twitter-vine/client'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Load support files
|
2
2
|
require 'twitter-vine'
|
3
|
+
require 'twitter-vine/client'
|
3
4
|
|
4
5
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
5
6
|
|
@@ -13,7 +14,7 @@ RSpec.configure do |config|
|
|
13
14
|
config.mock_with :rspec
|
14
15
|
end
|
15
16
|
|
16
|
-
TwitterVine.setup do |c|
|
17
|
+
TwitterVine::Client.setup do |c|
|
17
18
|
c.api_key = ENV["BT_TWITTER_API_KEY"]
|
18
19
|
c.api_secret = ENV["BT_TWITTER_API_SECRET"]
|
19
20
|
c.oauth_token = ENV["BT_TWITTER_OAUTH_TOKEN"]
|
@@ -31,3 +32,17 @@ class MockTweetWithHttpVineUrl
|
|
31
32
|
def urls;[{display_url:"vine.co/v/hF7WOEl76T1", expanded_url:"http://vine.co/v/hF7WOEl76T1"}];end
|
32
33
|
end
|
33
34
|
|
35
|
+
shared_context "vine results" do
|
36
|
+
|
37
|
+
def expect_results(vine_map)
|
38
|
+
puts vine_map
|
39
|
+
vine_map[:vine_id].should_not be nil
|
40
|
+
vine_map[:vine_url].should_not be nil
|
41
|
+
vine_map[:vine_thumbnail].should_not be nil
|
42
|
+
vine_map[:vine_author_thumbnail].should_not be nil
|
43
|
+
vine_map[:vine_author].should_not be nil
|
44
|
+
vine_map[:vine_description].should_not be nil
|
45
|
+
vine_map[:vine_src].should_not be nil
|
46
|
+
vine_map[:vine_type].should_not be nil
|
47
|
+
end
|
48
|
+
end
|
data/spec/twitter-vine_spec.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'twitter-vine'
|
3
|
+
require 'twitter-vine/client'
|
3
4
|
|
4
|
-
TwitterVine::
|
5
|
+
TwitterVine::DEBUG=true
|
5
6
|
|
6
7
|
describe TwitterVine do
|
8
|
+
include_context "vine results"
|
9
|
+
|
7
10
|
it "should be valid" do
|
8
11
|
TwitterVine.should be_a(Module)
|
12
|
+
TwitterVine::Client.should be_a(Module)
|
9
13
|
end
|
10
14
|
|
11
15
|
# Commented out until I set environment variables out on travis-ci
|
@@ -16,28 +20,29 @@ describe TwitterVine do
|
|
16
20
|
# expect(l.size).to be > 0
|
17
21
|
# end
|
18
22
|
|
19
|
-
it "should be able to scrape Vine metadata" do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
it "should be able to scrape Vine metadata from a Twitter API result" do
|
24
|
+
expect_results(TwitterVine::Client.send :build_vine_map, MockTweet.new)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to scrape Vine metadata from a Twitter API result even if expanded_url is http instead of https" do
|
28
|
+
expect_results(TwitterVine::Client.send :build_vine_map, MockTweetWithHttpVineUrl.new)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "can parse a direct vine url" do
|
32
|
+
expect_results(TwitterVine.parse("https://vine.co/v/b2BPEL0Orbm"))
|
29
33
|
end
|
30
34
|
|
31
|
-
it "
|
32
|
-
|
33
|
-
puts vine_map
|
34
|
-
vine_map[:vine_id].should_not be nil
|
35
|
-
vine_map[:vine_url].should_not be nil
|
36
|
-
vine_map[:vine_author_thumbnail].should_not be nil
|
37
|
-
vine_map[:vine_author].should_not be nil
|
38
|
-
vine_map[:vine_description].should_not be nil
|
39
|
-
vine_map[:vine_src].should_not be nil
|
40
|
-
vine_map[:vine_type].should_not be nil
|
35
|
+
it "can parse a direct vine url that is mistakenly http" do
|
36
|
+
expect_results(TwitterVine.parse("http://vine.co/v/b2BPEL0Orbm"))
|
41
37
|
end
|
42
38
|
|
39
|
+
it "can parse an accidental embed/simple vine url" do
|
40
|
+
expect_results(TwitterVine.parse("https://vine.co/v/b2BPEL0Orbm/embed/simple"))
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can parse an accidental embed/simple vine url that is double mistaken with http" do
|
44
|
+
expect_results(TwitterVine.parse("http://vine.co/v/b2BPEL0Orbm/embed/simple"))
|
45
|
+
end
|
46
|
+
|
47
|
+
|
43
48
|
end
|