bitly_exporter 0.0.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../support/matchers/a_link_with_matcher'
3
+
4
+ describe BitlyExporter::Exporter do
5
+ let(:oauth_token) { "asdlkfjasd134i1ojfasldkrj234aslkdjfq3249" }
6
+ let(:user) { BitlyExporter::User.new(oauth_token) }
7
+
8
+ context "with a maximum" do
9
+ let(:max) { 200 }
10
+
11
+ subject do
12
+ VCR.use_cassette "with maximum" do
13
+ BitlyExporter::Exporter.new(user).export(false, 200)
14
+ end
15
+ end
16
+
17
+ it "should retrieve the maximum" do
18
+ expect(subject).to have(200).items
19
+ end
20
+ end
21
+
22
+ context "no maximum" do
23
+ subject do
24
+ VCR.use_cassette "no maximum" do
25
+ BitlyExporter::Exporter.new(user).export
26
+ end
27
+ end
28
+
29
+ it "retrieves all of the links" do
30
+ subject
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../support/contexts/oauth_context'
3
+
4
+
5
+ describe BitlyExporter::Client do
6
+ include_context "oauth"
7
+ subject { BitlyExporter::Client.new(oauth_token) }
8
+
9
+ it "assigns oauth_token" do
10
+ subject { assigns(:oauth_token).to eq(oauth_token) }
11
+ end
12
+
13
+ it "assigns params" do
14
+ subject { assigns(:params).to eq({ access_token: oauth_token}) }
15
+ end
16
+
17
+ describe "#make_request" do
18
+ let(:api_url) { BitlyExporter::Client::API_URL }
19
+ let(:endpoint) { 'test' }
20
+ let(:body) { '{ "key":"value" }' }
21
+ let(:hash) { JSON.parse(body) }
22
+ let(:response) { double( code: 200, body: body) }
23
+
24
+ before do
25
+ HTTParty.stub(:get).with("#{api_url}#{endpoint}", query: subject.params).and_return(response)
26
+ end
27
+
28
+ it "returns a parsed response body" do
29
+ expect(subject.send(:make_request, endpoint)).to include(hash)
30
+ end
31
+
32
+ context "bad request" do
33
+ let(:response) { double(code: 404, body: body, message: 'No endpoint!') }
34
+
35
+ it "raises an exception" do
36
+ expect { subject.send(:make_request, endpoint) }.to raise_error(StandardError)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,48 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../support/contexts/oauth_context'
3
+ require_relative '../support/contexts/link_history_response_context'
4
+ require_relative '../support/matchers/a_link_with_matcher'
5
+
6
+ describe BitlyExporter::Exporter do
7
+ include_context 'oauth'
8
+ include_context 'link history response'
9
+ let(:empty_response) {
10
+ { "data" => {
11
+ "result_count" => 0, "link_history" => []
12
+ }
13
+ }
14
+ }
15
+ let(:user) { BitlyExporter::User.new(oauth_token) }
16
+
17
+ before do
18
+ BitlyExporter::User.any_instance.stub(:make_request).and_return(response, empty_response)
19
+ end
20
+
21
+ subject { BitlyExporter::Exporter.new(user) }
22
+
23
+ it "takes a user" do
24
+ expect(subject.user).to be(user)
25
+ end
26
+
27
+ describe '#export' do
28
+ it "returns all links" do
29
+ expect(subject.export).to have(2).items
30
+ end
31
+
32
+ it "contains the first link" do
33
+ expect(subject.export).to include(a_link_with link_data["link"])
34
+ end
35
+
36
+ it "contains the second link" do
37
+ expect(subject.export).to include(a_link_with link_data_2["link"])
38
+ end
39
+
40
+ it "accepts progress & max arguments" do
41
+ expect(subject.export(false, 100)).to include(a_link_with link_data_2["link"])
42
+ end
43
+
44
+ it "yields a block with the link" do
45
+ expect { |link| subject.export(&link) }.to yield_successive_args(BitlyExporter::Link, BitlyExporter::Link)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../support/contexts/link_history_response_context'
3
+
4
+ describe BitlyExporter::Link do
5
+ include_context 'link history response'
6
+
7
+ subject { BitlyExporter::Link.new(link_data) }
8
+
9
+ it { expect(subject.link).to eq(link_data["link"]) }
10
+ it { expect(subject.long_url).to eq(link_data["long_url"]) }
11
+ it { expect(subject.aggregate_link).to eq(link_data["aggregate_link"]) }
12
+ it { expect(subject.title).to eq(link_data["title"]) }
13
+ it { expect(subject.private).to eq(link_data["private"]) }
14
+ it { expect(subject.created_at).to eq(Time.at(link_data["created_at"])) }
15
+ it { expect(subject.modified_at).to eq(Time.at(link_data["modified_at"])) }
16
+
17
+ context "missing data" do
18
+ let(:link_data) {
19
+ {
20
+ "link" => "http://4sq.com/xnRb5V",
21
+ "long_url" => "http://foursquare.com/"
22
+ }
23
+ }
24
+
25
+ it { expect(subject.link).to eq(link_data["link"]) }
26
+ it { expect(subject.long_url).to eq(link_data["long_url"]) }
27
+ it { expect(subject.aggregate_link).to be_nil }
28
+ it { expect(subject.created_at).to be_nil }
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../support/contexts/oauth_context'
3
+ require_relative '../support/contexts/link_history_response_context'
4
+
5
+ describe BitlyExporter::User do
6
+ include_context 'oauth'
7
+
8
+ before do
9
+ BitlyExporter::User.any_instance.stub(:make_request).and_return(response)
10
+ end
11
+
12
+ subject { BitlyExporter::User.new(oauth_token) }
13
+
14
+ describe '#link_history' do
15
+ include_context 'link history response'
16
+
17
+ it "creates links" do
18
+ BitlyExporter::Link.should_receive(:new).twice
19
+ subject.link_history
20
+ end
21
+
22
+ it "returns result_count with links" do
23
+ expect(subject.link_history).to include(result_count)
24
+ end
25
+ end
26
+
27
+ describe '#info' do
28
+ let(:response) { double().as_null_object }
29
+
30
+ it 'requests user info' do
31
+ subject.should_receive(:make_request).with("/user/info")
32
+ subject.info
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ require 'coveralls'
2
+ Coveralls.wear! if ENV["COVERAGE"]
3
+
4
+ require 'bitly_exporter'
5
+ require 'vcr'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
9
+ c.hook_into :webmock
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.before(:each) do
14
+ BitlyExporter::Exporter.any_instance.stub(:sleep)
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ shared_context "link history response" do
2
+ let(:result_count) { 2 }
3
+ let(:response) {
4
+ { "data" =>
5
+ {
6
+ "result_count" => result_count,
7
+ "link_history" => [
8
+ {
9
+ "aggregate_link" => "http://4sq.com/bGUucR",
10
+ "archived" => false,
11
+ "client_id" => "a5a2e024b030d6a594be866c7be57b5e2dff9972",
12
+ "created_at" => 1331669360,
13
+ "link" => "http://4sq.com/xnRb5V",
14
+ "long_url" => "http://foursquare.com/",
15
+ "modified_at" => 1331669360,
16
+ "private" => false,
17
+ "title" => nil,
18
+ "user_ts" => 1331669360
19
+ },
20
+ {
21
+ "aggregate_link" => "http://nyti.ms/16tOHV",
22
+ "archived" => false,
23
+ "client_id" => "a5a2e024b030d6a594be866c7be57b5e2dff9972",
24
+ "created_at" => 1331669349,
25
+ "link" => "http://nyti.ms/xr5jgq",
26
+ "long_url" => "http://nytimes.com/",
27
+ "modified_at" => 1331669350,
28
+ "private" => false,
29
+ "title" => "The New York Times - Breaking News, World News & Multimedia",
30
+ "user_ts" => 1331669349
31
+ }
32
+ ]
33
+ }
34
+ }
35
+ }
36
+ let(:link_data) { response["data"]["link_history"][0] }
37
+ let(:link_data_2) { response["data"]["link_history"][1] }
38
+ end
@@ -0,0 +1,3 @@
1
+ shared_context "oauth" do
2
+ let(:oauth_token) { "asdlkfjasd134i1ojfasldkrj234aslkdjfq3249" }
3
+ end
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :a_link_with do |expected|
2
+ match do |actual|
3
+ actual.is_a?(BitlyExporter::Link) && (actual.link == expected)
4
+ end
5
+ description do
6
+ "a short link '#{expected}'"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitly_exporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Ortbals
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
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: vcr
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: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
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: Export a user's links from Bitly.
98
+ email:
99
+ - me@aaronortbals.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - bitly_exporter.gemspec
111
+ - lib/bitly_exporter.rb
112
+ - lib/bitly_exporter/client.rb
113
+ - lib/bitly_exporter/exporter.rb
114
+ - lib/bitly_exporter/link.rb
115
+ - lib/bitly_exporter/user.rb
116
+ - lib/bitly_exporter/version.rb
117
+ - spec/fixtures/cassettes/no_maximum.yml
118
+ - spec/fixtures/cassettes/with_maximum.yml
119
+ - spec/integration/exporter_spec.rb
120
+ - spec/lib/client_spec.rb
121
+ - spec/lib/exporter_spec.rb
122
+ - spec/lib/link_spec.rb
123
+ - spec/lib/user_spec.rb
124
+ - spec/spec_helper.rb
125
+ - spec/support/contexts/link_history_response_context.rb
126
+ - spec/support/contexts/oauth_context.rb
127
+ - spec/support/matchers/a_link_with_matcher.rb
128
+ homepage: https://github.com/aortbals/bitly_exporter
129
+ licenses: []
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>'
143
+ - !ruby/object:Gem::Version
144
+ version: 1.3.1
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.0.3
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Supports Bitly API V3
151
+ test_files:
152
+ - spec/fixtures/cassettes/no_maximum.yml
153
+ - spec/fixtures/cassettes/with_maximum.yml
154
+ - spec/integration/exporter_spec.rb
155
+ - spec/lib/client_spec.rb
156
+ - spec/lib/exporter_spec.rb
157
+ - spec/lib/link_spec.rb
158
+ - spec/lib/user_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support/contexts/link_history_response_context.rb
161
+ - spec/support/contexts/oauth_context.rb
162
+ - spec/support/matchers/a_link_with_matcher.rb
163
+ has_rdoc: