gnip_api 1.1.3 → 1.2.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +16 -37
- data/lib/gnip_api/adapter.rb +42 -28
- data/lib/gnip_api/configuration.rb +4 -6
- data/lib/gnip_api/errors.rb +3 -0
- data/lib/gnip_api/gnip/gnip_data.rb +1 -1
- data/lib/gnip_api/gnip/system_message.rb +4 -0
- data/lib/gnip_api/power_track/buffer.rb +42 -0
- data/lib/gnip_api/power_track/rule.rb +77 -0
- data/lib/gnip_api/power_track/rule_validator.rb +6 -0
- data/lib/gnip_api/power_track/rules.rb +81 -0
- data/lib/gnip_api/power_track/stream.rb +122 -0
- data/lib/gnip_api/request.rb +8 -1
- data/lib/gnip_api/response.rb +21 -0
- data/lib/gnip_api/search.rb +108 -0
- data/lib/gnip_api/version.rb +1 -1
- data/lib/gnip_api.rb +5 -7
- data/spec/fixtures/rule_value_examples.json +27 -0
- data/spec/gnip_api/adapter_spec.rb +0 -87
- data/spec/gnip_api/configuration_spec.rb +0 -15
- data/spec/gnip_api/{apis/power_track → power_track}/buffer_spec.rb +2 -2
- data/spec/gnip_api/power_track/rule_spec.rb +89 -0
- data/spec/gnip_api/{apis/power_track → power_track}/rules_spec.rb +8 -8
- data/spec/gnip_api/power_track/stream_spec.rb +53 -0
- data/spec/gnip_api/response_spec.rb +27 -0
- data/spec/gnip_api/{apis/search_spec.rb → search_spec.rb} +9 -9
- data/spec/spec_helper.rb +4 -3
- metadata +20 -26
- data/lib/gnip_api/adapters/base_adapter.rb +0 -94
- data/lib/gnip_api/adapters/httparty_adapter.rb +0 -65
- data/lib/gnip_api/apis/power_track/buffer.rb +0 -38
- data/lib/gnip_api/apis/power_track/rule.rb +0 -33
- data/lib/gnip_api/apis/power_track/rule_validator.rb +0 -8
- data/lib/gnip_api/apis/power_track/rules.rb +0 -83
- data/lib/gnip_api/apis/power_track/stream.rb +0 -84
- data/lib/gnip_api/apis/search.rb +0 -109
- data/spec/gnip_api/adapters/base_adapter_spec.rb +0 -0
- data/spec/gnip_api/adapters/httparty_adapter_spec.rb +0 -0
- data/spec/gnip_api/apis/power_track/rule_spec.rb +0 -62
- data/spec/gnip_api/apis/power_track/stream_spec.rb +0 -93
- data/spec/lib/test_adapter.rb +0 -16
@@ -1,62 +0,0 @@
|
|
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
|
@@ -1,93 +0,0 @@
|
|
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
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#initialize' do
|
10
|
-
it 'throws GnipApi::Errors::Configuration::InvalidOutputFormat when not included' do
|
11
|
-
GnipApi.configuration.stream_output_format = :invalid
|
12
|
-
expect(Proc.new{GnipApi::Apis::PowerTrack::Stream.new}).to raise_error(GnipApi::Errors::Configuration::InvalidOutputFormat)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#process_entries' do
|
17
|
-
before do
|
18
|
-
@json = File.read('spec/fixtures/activities/real_activity.json')
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when output format is :activity' do
|
22
|
-
it 'bulds a Message object from the json' do
|
23
|
-
message = @stream.process_entries([@json])
|
24
|
-
expect(message.first.class).to eq(Gnip::Activity)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns empty array if could not parse json' do
|
28
|
-
message = @stream.process_entries(['lol'])
|
29
|
-
expect(message).to eq([])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when output format is :parsed_json' do
|
34
|
-
before do
|
35
|
-
GnipApi.configuration.stream_output_format = :parsed_json
|
36
|
-
@stream = GnipApi::Apis::PowerTrack::Stream.new
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'parses json' do
|
40
|
-
message = @stream.process_entries([@json])
|
41
|
-
expect(message.first.class).to eq(Hash)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns empty array if could not parse json' do
|
45
|
-
message = @stream.process_entries(['lol'])
|
46
|
-
expect(message).to eq([])
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when output format is :json' do
|
51
|
-
before do
|
52
|
-
GnipApi.configuration.stream_output_format = :json
|
53
|
-
@stream = GnipApi::Apis::PowerTrack::Stream.new
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'returns raw json' do
|
57
|
-
message = @stream.process_entries([@json])
|
58
|
-
expect(message.first.class).to eq(String)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'returns whatever stream returns' do
|
62
|
-
message = @stream.process_entries(['lol'])
|
63
|
-
expect(message).to eq(['lol'])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '#parse_json' do
|
69
|
-
before do
|
70
|
-
@json = File.read('spec/fixtures/activities/real_activity.json')
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'does not throw error with activity json' do
|
74
|
-
expect(Proc.new{@stream.parse_json(@json)}).not_to raise_error
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'parses json' do
|
78
|
-
parsed = @stream.parse_json @json
|
79
|
-
expect(parsed.class).to eq(Hash)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'returns nil if empty json is passed' do
|
83
|
-
parsed = @stream.parse_json('')
|
84
|
-
expect(parsed).to eq(nil)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'returns nil if invalid json is passed' do
|
88
|
-
parsed = @stream.parse_json('12,4.,x_VZxuv8{ak{f}}}}} {{ (d(s)aa(((aaaaa)aaa)')
|
89
|
-
expect(parsed).to eq(nil)
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|
data/spec/lib/test_adapter.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class TestAdapter
|
2
|
-
def post request
|
3
|
-
return GnipApi::Response.new(request, 200, 'post_result', {:status => 'OK'})
|
4
|
-
end
|
5
|
-
|
6
|
-
def delete request
|
7
|
-
return GnipApi::Response.new(request, 200, 'delete_result', {:status => 'OK'})
|
8
|
-
end
|
9
|
-
|
10
|
-
def get request
|
11
|
-
return GnipApi::Response.new(request, 200, 'get_result', {:status => 'OK'})
|
12
|
-
end
|
13
|
-
|
14
|
-
def stream_get request
|
15
|
-
end
|
16
|
-
end
|