gnip_api 0.0.1 → 0.0.2

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile.lock +6 -1
  6. data/README.md +43 -4
  7. data/gnip_api.gemspec +1 -0
  8. data/lib/gnip_api/adapter.rb +44 -22
  9. data/lib/gnip_api/adapters/base_adapter.rb +59 -0
  10. data/lib/gnip_api/adapters/httparty_adapter.rb +33 -1
  11. data/lib/gnip_api/apis/power_track/buffer.rb +4 -0
  12. data/lib/gnip_api/apis/power_track/rule.rb +31 -0
  13. data/lib/gnip_api/apis/power_track/rules.rb +69 -2
  14. data/lib/gnip_api/apis/power_track/stream.rb +41 -22
  15. data/lib/gnip_api/apis/search/count.rb +0 -0
  16. data/lib/gnip_api/apis/search/query.rb +36 -0
  17. data/lib/gnip_api/apis/search/result.rb +17 -0
  18. data/lib/gnip_api/apis/search/stream.rb +26 -0
  19. data/lib/gnip_api/configuration.rb +4 -1
  20. data/lib/gnip_api/endpoints.rb +15 -2
  21. data/lib/gnip_api/errors.rb +39 -0
  22. data/lib/gnip_api/gnip/activity.rb +72 -0
  23. data/lib/gnip_api/gnip/actor.rb +42 -11
  24. data/lib/gnip_api/gnip/gnip_data.rb +23 -0
  25. data/lib/gnip_api/gnip/message.rb +24 -51
  26. data/lib/gnip_api/gnip/system_message.rb +30 -0
  27. data/lib/gnip_api/gnip/url.rb +35 -0
  28. data/lib/gnip_api/limiters/rules.rb +56 -0
  29. data/lib/gnip_api/rate_limiter.rb +14 -0
  30. data/lib/gnip_api/request.rb +26 -0
  31. data/lib/gnip_api/response.rb +35 -0
  32. data/lib/gnip_api/version.rb +1 -1
  33. data/lib/gnip_api.rb +31 -0
  34. data/spec/fixtures/activities/full_activity.json +227 -0
  35. data/spec/fixtures/activities/nil_urls.json +1 -0
  36. data/spec/fixtures/activities/real_activity.json +127 -0
  37. data/spec/fixtures/activities/real_activity_long_rules.json +126 -0
  38. data/spec/fixtures/system_messages/error.json +1 -0
  39. data/spec/fixtures/system_messages/info.json +1 -0
  40. data/spec/fixtures/system_messages/warn.json +1 -0
  41. data/spec/fixtures/twitter_messages/quote.json +219 -0
  42. data/spec/fixtures/twitter_messages/retweet.json +418 -0
  43. data/spec/fixtures/twitter_messages/retweet_long_rules.json +417 -0
  44. data/spec/fixtures/twitter_messages/scrub_geo.json +11 -0
  45. data/spec/fixtures/twitter_messages/status_delete.json +11 -0
  46. data/spec/fixtures/twitter_messages/status_withheld.json +11 -0
  47. data/spec/fixtures/twitter_messages/tweet.json +233 -0
  48. data/spec/fixtures/twitter_messages/tweet_long_rules.json +232 -0
  49. data/spec/fixtures/twitter_messages/user_delete.json +7 -0
  50. data/spec/fixtures/twitter_messages/user_protect.json +7 -0
  51. data/spec/fixtures/twitter_messages/user_suspend.json +7 -0
  52. data/spec/fixtures/twitter_messages/user_undelete.json +7 -0
  53. data/spec/fixtures/twitter_messages/user_unprotect.json +7 -0
  54. data/spec/fixtures/twitter_messages/user_unsuspend.json +7 -0
  55. data/spec/fixtures/twitter_messages/user_withheld.json +10 -0
  56. data/spec/gnip_api/adapter_spec.rb +78 -0
  57. data/spec/gnip_api/adapters/base_adapter_spec.rb +0 -0
  58. data/spec/gnip_api/adapters/httparty_adapter_spec.rb +0 -0
  59. data/spec/gnip_api/apis/power_track/rule_spec.rb +62 -0
  60. data/spec/gnip_api/apis/power_track/rules_spec.rb +70 -0
  61. data/spec/gnip_api/apis/power_track/stream_spec.rb +50 -0
  62. data/spec/gnip_api/gnip/activity_spec.rb +123 -0
  63. data/spec/gnip_api/gnip/gnip_data_spec.rb +108 -0
  64. data/spec/gnip_api/gnip/message_spec.rb +48 -0
  65. data/spec/gnip_api/limiters/rules_spec.rb +74 -0
  66. data/spec/gnip_api/request_spec.rb +33 -0
  67. data/spec/gnip_api/response_spec.rb +32 -0
  68. data/spec/lib/test_adapter.rb +16 -0
  69. data/spec/spec_helper.rb +8 -0
  70. metadata +103 -2
@@ -0,0 +1,232 @@
1
+ {
2
+ "id": "tag:search.twitter.com,2005:593895901623496704",
3
+ "objectType": "activity",
4
+ "actor": {
5
+ "objectType": "person",
6
+ "id": "id:twitter.com:2993982541",
7
+ "link": "http://www.twitter.com/jondee_test",
8
+ "displayName": "Test Demo",
9
+ "postedTime": "2015-01-24T00:12:53.000Z",
10
+ "image": "https://pbs.twimg.com/profile_images/593893018911907840/YM9oLru3_normal.png",
11
+ "summary": "this is a test account.",
12
+ "links": [
13
+ {
14
+ "href": null,
15
+ "rel": "me"
16
+ }
17
+ ],
18
+ "friendsCount": 43,
19
+ "followersCount": 2,
20
+ "listedCount": 0,
21
+ "statusesCount": 30,
22
+ "twitterTimeZone": "Mountain Time (US & Canada)",
23
+ "verified": false,
24
+ "utcOffset": "-21600",
25
+ "preferredUsername": "jondee_test",
26
+ "languages": [
27
+ "en"
28
+ ],
29
+ "location": {
30
+ "objectType": "place",
31
+ "displayName": "Denver, CO"
32
+ },
33
+ "favoritesCount": 0
34
+ },
35
+ "verb": "post",
36
+ "postedTime": "2015-04-30T21:53:11.000Z",
37
+ "generator": {
38
+ "displayName": "Twitter Web Client",
39
+ "link": "http://twitter.com"
40
+ },
41
+ "provider": {
42
+ "objectType": "service",
43
+ "displayName": "Twitter",
44
+ "link": "http://www.twitter.com"
45
+ },
46
+ "link": "http://twitter.com/jondee_test/statuses/593895901623496704",
47
+ "body": "This is a #test tweet @LoveforTestingT with an image. http://t.co/ZvgHovKZq4",
48
+ "object": {
49
+ "objectType": "note",
50
+ "id": "object:search.twitter.com,2005:593895901623496704",
51
+ "summary": "This is a #test tweet @LoveforTestingT with an image. http://t.co/ZvgHovKZq4",
52
+ "link": "http://twitter.com/jondee_test/statuses/593895901623496704",
53
+ "postedTime": "2015-04-30T21:53:11.000Z"
54
+ },
55
+ "favoritesCount": 0,
56
+ "location": {
57
+ "objectType": "place",
58
+ "displayName": "Boulder, CO",
59
+ "name": "Boulder",
60
+ "country_code": "United States",
61
+ "twitter_country_code": "US",
62
+ "link": "https://api.twitter.com/1.1/geo/id/fd70c22040963ac7.json",
63
+ "geo": {
64
+ "type": "Polygon",
65
+ "coordinates": [
66
+ [
67
+ [
68
+ -105.3017759,
69
+ 39.953552
70
+ ],
71
+ [
72
+ -105.3017759,
73
+ 40.094411
74
+ ],
75
+ [
76
+ -105.183597,
77
+ 40.094411
78
+ ],
79
+ [
80
+ -105.183597,
81
+ 39.953552
82
+ ]
83
+ ]
84
+ ]
85
+ },
86
+ "twitter_place_type": "city"
87
+ },
88
+ "twitter_entities": {
89
+ "hashtags": [
90
+ {
91
+ "text": "test",
92
+ "indices": [
93
+ 10,
94
+ 15
95
+ ]
96
+ }
97
+ ],
98
+ "trends": [],
99
+ "urls": [],
100
+ "user_mentions": [
101
+ {
102
+ "screen_name": "LoveforTestingT",
103
+ "name": "Leah ",
104
+ "id": 2432909010,
105
+ "id_str": "2432909010",
106
+ "indices": [
107
+ 22,
108
+ 38
109
+ ]
110
+ }
111
+ ],
112
+ "symbols": [],
113
+ "media": [
114
+ {
115
+ "id": 593895901145346000,
116
+ "id_str": "593895901145346048",
117
+ "indices": [
118
+ 54,
119
+ 76
120
+ ],
121
+ "media_url": "http://pbs.twimg.com/media/CD3xLO1UMAAvBgO.png",
122
+ "media_url_https": "https://pbs.twimg.com/media/CD3xLO1UMAAvBgO.png",
123
+ "url": "http://t.co/ZvgHovKZq4",
124
+ "display_url": "pic.twitter.com/ZvgHovKZq4",
125
+ "expanded_url": "http://twitter.com/johnd_test/status/593895901623496704/photo/1",
126
+ "type": "photo",
127
+ "sizes": {
128
+ "small": {
129
+ "w": 340,
130
+ "h": 340,
131
+ "resize": "fit"
132
+ },
133
+ "thumb": {
134
+ "w": 150,
135
+ "h": 150,
136
+ "resize": "crop"
137
+ },
138
+ "large": {
139
+ "w": 512,
140
+ "h": 512,
141
+ "resize": "fit"
142
+ },
143
+ "medium": {
144
+ "w": 512,
145
+ "h": 512,
146
+ "resize": "fit"
147
+ }
148
+ }
149
+ }
150
+ ]
151
+ },
152
+ "twitter_extended_entities": {
153
+ "media": [
154
+ {
155
+ "id": 593895901145346000,
156
+ "id_str": "593895901145346048",
157
+ "indices": [
158
+ 54,
159
+ 76
160
+ ],
161
+ "media_url": "http://pbs.twimg.com/media/CD3xLO1UMAAvBgO.png",
162
+ "media_url_https": "https://pbs.twimg.com/media/CD3xLO1UMAAvBgO.png",
163
+ "url": "http://t.co/ZvgHovKZq4",
164
+ "display_url": "pic.twitter.com/ZvgHovKZq4",
165
+ "expanded_url": "http://twitter.com/johnd_test/status/593895901623496704/photo/1",
166
+ "type": "photo",
167
+ "sizes": {
168
+ "small": {
169
+ "w": 340,
170
+ "h": 340,
171
+ "resize": "fit"
172
+ },
173
+ "thumb": {
174
+ "w": 150,
175
+ "h": 150,
176
+ "resize": "crop"
177
+ },
178
+ "large": {
179
+ "w": 512,
180
+ "h": 512,
181
+ "resize": "fit"
182
+ },
183
+ "medium": {
184
+ "w": 512,
185
+ "h": 512,
186
+ "resize": "fit"
187
+ }
188
+ }
189
+ }
190
+ ]
191
+ },
192
+ "twitter_filter_level": "low",
193
+ "twitter_lang": "en",
194
+ "retweetCount": 0,
195
+ "gnip": {
196
+ "matching_rules": [
197
+ {
198
+ "tag": "something"
199
+ }
200
+ ],
201
+ "urls": [
202
+ {
203
+ "url": "http://t.co/ZvgHovKZq4",
204
+ "expanded_url": "http://twitter.com/johnd_test/status/593895901623496704/photo/1",
205
+ "expanded_status": 200
206
+ }
207
+ ],
208
+ "language": {
209
+ "value": "en"
210
+ },
211
+ "profileLocations": [
212
+ {
213
+ "objectType": "place",
214
+ "geo": {
215
+ "type": "point",
216
+ "coordinates": [
217
+ -104.9847,
218
+ 39.73915
219
+ ]
220
+ },
221
+ "address": {
222
+ "country": "United States",
223
+ "countryCode": "US",
224
+ "locality": "Denver",
225
+ "region": "Colorado",
226
+ "subRegion": "Denver County"
227
+ },
228
+ "displayName": "Denver, Colorado, United States"
229
+ }
230
+ ]
231
+ }
232
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "verb": "user_delete",
3
+ "object": {
4
+ "id": "tag:search.twitter.com,2012:user\/1602954684"
5
+ },
6
+ "timestampMs": "2014-08-27T23:49:40.532+00:00"
7
+ }
@@ -0,0 +1,7 @@
1
+
2
+ "verb": "user_protect",
3
+ "object": {
4
+ "id": "tag:search.twitter.com,2012:user\/930913333"
5
+ },
6
+ "timestampMs": "2014-08-27T23:49:41.839+00:00"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "verb": "user_suspend",
3
+ "object": {
4
+ "id": "tag:search.twitter.com,2012:user\/930913333"
5
+ },
6
+ "timestampMs": "2014-08-27T23:49:41.839+00:00"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "verb": "user_undelete",
3
+ "object": {
4
+ "id": "tag:search.twitter.com,2012:user\/930913333"
5
+ },
6
+ "timestampMs": "2014-08-27T23:49:41.839+00:00"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "verb": "user_unprotect",
3
+ "object": {
4
+ "id": "tag:search.twitter.com,2012:user\/930913333"
5
+ },
6
+ "timestampMs": "2014-08-27T23:49:41.839+00:00"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "verb": "user_unsuspend",
3
+ "object": {
4
+ "id": "tag:search.twitter.com,2012:user\/930913333"
5
+ },
6
+ "timestampMs": "2014-08-27T23:49:41.839+00:00"
7
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "verb": "user_withheld",
3
+ "object": {
4
+ "id": "tag:search.twitter.com,2012:user\/1375036644"
5
+ },
6
+ "withheld_in_countries": [
7
+ "XY"
8
+ ],
9
+ "timestampMs": "2014-08-27T23:49:41.839+00:00"
10
+ }
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe GnipApi::Adapter do
4
+ before do
5
+ @uri = URI('http://somwhere.com')
6
+ end
7
+
8
+ it 'raises error if no credentials defined' do
9
+ GnipApi.configure do |c|
10
+ c.user = nil
11
+ c.password = nil
12
+ c.account = nil
13
+ end
14
+ expect(Proc.new{GnipApi::Adapter.new}).to raise_error(GnipApi::Errors::MissingCredentials)
15
+ end
16
+
17
+ it 'raises error if no adapter is selected' do
18
+ GnipApi.configure do |c|
19
+ c.user = 'somebody'
20
+ c.password = 'something'
21
+ c.account = 'lol'
22
+ c.adapter_class = nil
23
+ end
24
+
25
+ expect(Proc.new{GnipApi::Adapter.new}).to raise_error(GnipApi::Errors::MissingAdapter)
26
+ end
27
+
28
+ it 'does not raise error when credentials and adapter are present' do
29
+ configure_gem
30
+ expect(Proc.new{GnipApi::Adapter.new}).not_to raise_error
31
+ end
32
+
33
+ it 'uses adapter selected' do
34
+ configure_gem
35
+ GnipApi.configuration.adapter_class = TestAdapter
36
+ expect(GnipApi::Adapter.new.adapter.class).to eq(TestAdapter)
37
+ end
38
+
39
+ describe '#get' do
40
+ before do
41
+ configure_gem
42
+ @adapter = GnipApi::Adapter.new
43
+ @request = GnipApi::Request.new_get(@uri)
44
+ end
45
+
46
+ it 'returns a body' do
47
+ result = @adapter.get @request
48
+ expect(result).to eq('get_result') # Defined at spec/lib/test_adapter.rb
49
+ end
50
+ end
51
+
52
+ describe '#post' do
53
+ before do
54
+ configure_gem
55
+ @adapter = GnipApi::Adapter.new
56
+ @request = GnipApi::Request.new_post(@uri, 'some_payload')
57
+ end
58
+
59
+ it 'returns a body' do
60
+ result = @adapter.post @request
61
+ expect(result).to eq('post_result') # Defined at spec/lib/test_adapter.rb
62
+ end
63
+ end
64
+
65
+ describe '#delete' do
66
+ before do
67
+ configure_gem
68
+ @adapter = GnipApi::Adapter.new
69
+ @request = GnipApi::Request.new_delete(@uri, 'some_payload')
70
+ end
71
+
72
+ it 'returns a body' do
73
+ result = @adapter.delete @request
74
+ expect(result).to eq('delete_result') # Defined at spec/lib/test_adapter.rb
75
+ end
76
+ end
77
+
78
+ end
File without changes
File without changes
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe GnipApi::Apis::PowerTrack::Rule do
4
+ before do
5
+ configure_gem
6
+ end
7
+
8
+ it 'creates a rule' do
9
+ expect(Proc.new{GnipApi::Apis::PowerTrack::Rule.new}).not_to raise_error
10
+ end
11
+
12
+ describe 'rule' do
13
+ before do
14
+ @value = 'something'
15
+ @tag = 'tag'
16
+ @rule = GnipApi::Apis::PowerTrack::Rule.new :value => @value, :tag => @tag
17
+ end
18
+
19
+ it 'has a value' do
20
+ expect(@rule.value).to eq(@value)
21
+ end
22
+
23
+ it 'has a tag' do
24
+ expect(@rule.tag).to eq(@tag)
25
+ end
26
+ end
27
+
28
+ describe '#attributes' do
29
+ context 'with tag' do
30
+ before do
31
+ @rule = GnipApi::Apis::PowerTrack::Rule.new(:value => 'r1', :tag => 't1')
32
+ @attributes = {:value => 'r1', :tag => 't1'}
33
+ end
34
+
35
+ it 'returns hash with attributes' do
36
+ expect(@rule.attributes).to eq(@attributes)
37
+ end
38
+ end
39
+
40
+ context 'without tag' do
41
+ before do
42
+ @rule = GnipApi::Apis::PowerTrack::Rule.new(:value => 'r1')
43
+ @attributes = {:value => 'r1'}
44
+ end
45
+
46
+ it 'returns hash with attributes' do
47
+ expect(@rule.attributes).to eq(@attributes)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#to_json' do
53
+ before do
54
+ @rule = GnipApi::Apis::PowerTrack::Rule.new :value => 'value', :tag => 'tag'
55
+ @json = {:value => 'value', :tag => 'tag'}.to_json
56
+ end
57
+
58
+ it 'converts to json' do
59
+ expect(@rule.to_json).to eq(@json)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe GnipApi::Apis::PowerTrack::Rules do
4
+ before do
5
+ @api = GnipApi::Apis::PowerTrack::Rules.new(:source => 'source', :label => 'label')
6
+ @rules = [GnipApi::Apis::PowerTrack::Rule.new(:value => 'r1', :tag => 't1'),
7
+ GnipApi::Apis::PowerTrack::Rule.new(:value => 'r2')]
8
+ @json = {:rules => [{:value => 'r1', :tag => 't1'}, {:value => 'r2'}]}.to_json
9
+ end
10
+
11
+ describe '#parse_rules' do
12
+ it 'parses json rules to GnipApi::Apis::PowerTrack::Rule objects' do
13
+ parsed = @api.parse_rules(@json)
14
+ expect(parsed.first.class).to eq(GnipApi::Apis::PowerTrack::Rule)
15
+ end
16
+ end
17
+
18
+ describe '#construct_rules' do
19
+ it 'constructs valid rules' do
20
+ expect(@api.construct_rules(@rules)).to eq(@json)
21
+ end
22
+ end
23
+
24
+ describe '#delete' do
25
+ it 'raises error if no rules passed' do
26
+ expect(Proc.new{@api.delete([])}).to raise_error(GnipApi::Errors::PowerTrack::MissingRules)
27
+ end
28
+ end
29
+
30
+ describe '#create' do
31
+ it 'raises error if no rules passed' do
32
+ expect(Proc.new{@api.create([])}).to raise_error(GnipApi::Errors::PowerTrack::MissingRules)
33
+ end
34
+ end
35
+
36
+ describe '#list' do
37
+ before do
38
+ expect(@api.adapter).to receive(:get).and_return(@json)
39
+ end
40
+
41
+ it 'returns an array' do
42
+ result = @api.list
43
+ expect(result.kind_of?(Array)).to eq(true)
44
+ end
45
+
46
+ it 'gets 2 rules' do
47
+ result = @api.list
48
+ expect(result.size).to eq(2)
49
+ end
50
+
51
+ it 'returns GnipApi::Apis::PowerTrack::Rule objects' do
52
+ result = @api.list
53
+ expect(result.map(&:class).uniq).to eq([GnipApi::Apis::PowerTrack::Rule])
54
+ end
55
+
56
+ describe 'rules fetched' do
57
+ before do
58
+ @rules = @api.list
59
+ end
60
+
61
+ it 'contains expected values' do
62
+ expect(@rules.map(&:value)).to eq(['r1', 'r2'])
63
+ end
64
+
65
+ it 'contains expected tags' do
66
+ expect(@rules.map(&:tag)).to eq(['t1', nil])
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe GnipApi::Apis::PowerTrack::Stream do
4
+ before do
5
+ configure_gem
6
+ @stream = GnipApi::Apis::PowerTrack::Stream.new(:source => 'source', :stream => 'stream')
7
+ end
8
+
9
+ describe '#process_entries' do
10
+ before do
11
+ @json = File.read('spec/fixtures/activities/real_activity.json')
12
+ end
13
+
14
+ it 'bulds a Message object from the json' do
15
+ message = @stream.process_entries([@json])
16
+ expect(message.first.class).to eq(Gnip::Activity)
17
+ end
18
+
19
+ it 'returns empty array if could not parse json' do
20
+ message = @stream.process_entries(['lol'])
21
+ expect(message).to eq([])
22
+ end
23
+ end
24
+
25
+ describe '#parse_json' do
26
+ before do
27
+ @json = File.read('spec/fixtures/activities/real_activity.json')
28
+ end
29
+
30
+ it 'does not throw error with activity json' do
31
+ expect(Proc.new{@stream.parse_json(@json)}).not_to raise_error
32
+ end
33
+
34
+ it 'parses json' do
35
+ parsed = @stream.parse_json @json
36
+ expect(parsed.class).to eq(Hash)
37
+ end
38
+
39
+ it 'returns nil if empty json is passed' do
40
+ parsed = @stream.parse_json('')
41
+ expect(parsed).to eq(nil)
42
+ end
43
+
44
+ it 'returns nil if invalid json is passed' do
45
+ parsed = @stream.parse_json('12,4.,x_VZxuv8{ak{f}}}}} {{ (d(s)aa(((aaaaa)aaa)')
46
+ expect(parsed).to eq(nil)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gnip::Message do
4
+ context 'twitter' do
5
+ before do
6
+ @retweet_json = File.read(fixture_path.join('twitter_messages', 'retweet.json'))
7
+ @tweet_json = File.read(fixture_path.join('twitter_messages', 'tweet.json'))
8
+ @retweet_json_long_rules = File.read(fixture_path.join('twitter_messages', 'retweet_long_rules.json'))
9
+ @tweet_json_long_rules = File.read(fixture_path.join('twitter_messages', 'tweet_long_rules.json'))
10
+ @retweet = JSON.parse @retweet_json
11
+ @tweet = JSON.parse @tweet_json
12
+ @tweet_long_rules = JSON.parse @tweet_json_long_rules
13
+ @retweet_long_rules = JSON.parse @retweet_json_long_rules
14
+ end
15
+
16
+ it 'accepts retweet data' do
17
+ expect(Proc.new{Gnip::Activity.new(@retweet)}).not_to raise_error
18
+ end
19
+
20
+ it 'accepts tweet data' do
21
+ expect(Proc.new{Gnip::Activity.new(@tweet)}).not_to raise_error
22
+ end
23
+
24
+ it 'accepts tweet data with long rules' do
25
+ expect(Proc.new{Gnip::Activity.new(@tweet_long_rules)}).not_to raise_error
26
+ end
27
+
28
+ it 'accepts retweet data with long rules' do
29
+ expect(Proc.new{Gnip::Activity.new(@retweet_long_rules)}).not_to raise_error
30
+ end
31
+
32
+ context 'retweet' do
33
+ before do
34
+ @activity = Gnip::Activity.new @retweet
35
+ end
36
+
37
+ it 'has id' do
38
+ expect(@activity.id).to eq(@retweet['id'])
39
+ end
40
+
41
+ it 'parses network id' do
42
+ expect(@activity.tweet_id).to eq(@retweet['id'].split(':').last)
43
+ end
44
+
45
+ it 'has activity object type' do
46
+ expect(@activity.object_type).to eq('activity')
47
+ end
48
+
49
+ it 'has share as verb' do
50
+ expect(@activity.verb).to eq('share')
51
+ end
52
+
53
+ it 'has actor' do
54
+ expect(@activity.actor).not_to eq(nil)
55
+ end
56
+
57
+ it 'has Gnip::Actor object actor' do
58
+ expect(@activity.actor.class).to eq(Gnip::Actor)
59
+ end
60
+
61
+ it 'has posted_time' do
62
+ expect(@activity.posted_time).not_to eq(nil)
63
+ end
64
+
65
+ it 'has parsed posted_time' do
66
+ expect(@activity.posted_time.kind_of?(DateTime)).to eq(true)
67
+ end
68
+
69
+ it 'has generator data' do
70
+ expect(@activity.generator).not_to eq(nil)
71
+ end
72
+
73
+ it 'has provider data' do
74
+ expect(@activity.provider).not_to eq(nil)
75
+ end
76
+
77
+ it 'has link' do
78
+ expect(@activity.link).not_to eq(nil)
79
+ end
80
+
81
+ it 'has URI as link' do
82
+ expect(@activity.link.kind_of?(URI)).to eq(true)
83
+ end
84
+
85
+ it 'has body' do
86
+ expect(@activity.body).not_to eq(nil)
87
+ end
88
+
89
+ it 'has object' do
90
+ expect(@activity.object).not_to eq(nil)
91
+ end
92
+
93
+ it 'has another activity object as object' do
94
+ expect(@activity.object.class).to eq(Gnip::Activity)
95
+ end
96
+
97
+ it 'has favorites_count' do
98
+ expect(@activity.favorites_count).not_to eq(nil)
99
+ end
100
+
101
+ it 'has twitter_entities' do
102
+ expect(@activity.twitter_entities).not_to eq(nil)
103
+ end
104
+
105
+ it 'has tiwtter_filter_level' do
106
+ expect(@activity.twitter_filter_level).not_to eq(nil)
107
+ end
108
+
109
+ it 'has twitter_lang' do
110
+ expect(@activity.twitter_lang).not_to eq(nil)
111
+ end
112
+
113
+ it 'has retweet_count' do
114
+ expect(@activity.retweet_count).not_to eq(nil)
115
+ end
116
+
117
+ it 'has gnip data' do
118
+ expect(@activity.gnip).not_to eq(nil)
119
+ end
120
+
121
+ end
122
+ end
123
+ end