gnip-client 0.2.7 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c00b958351fc744e8b4c1784a75149efbbdc471
4
- data.tar.gz: '0619daee59e0e23ebe2effca3b803bc901a05bba'
3
+ metadata.gz: 10d62de62aef3c39ccb8e252fdc2a96475eccd6b
4
+ data.tar.gz: ce806b0202a126ea6d6a1ee8fda9783c4f56e909
5
5
  SHA512:
6
- metadata.gz: 5af9a3ab2012c761c7af1d3f9f676746504fd7404c6f3c8d3f3497077a96f6e2b2c255aa1dfba479fcf40de9dece4aac2a1e0996678a84b21491e1450551562e
7
- data.tar.gz: e98a1441eb81a7dffe40f55711aa58ecaa450f2bc366259e406ace0e81321483554223373bec64e2eb56d468581333ac481833ca68bf06ed275349e2dd5c1570
6
+ metadata.gz: 2ba8c066c65f17053cdd5b3272c68f10f6f33b3c0f34ee9fe3d6a84f3f9a12df7f36050a776f93dbe55d11bbb3445b7d661912c9c9578f4b27f49b28e08fa9ad
7
+ data.tar.gz: 3101f09f806928ee1b7ba400494885590bb071b7f84a6979dbfc46a6185d16e8e72ada65322c10255f6a74c46b125d38897ec8da4f4d979ee899f1ad75f01af3
@@ -1,21 +1,21 @@
1
1
  module Gnip
2
2
  module GnipFullArchive
3
3
  class FullArchive
4
-
4
+
5
5
  class InvalidRequestException < StandardError; end
6
-
6
+
7
7
  include HTTParty
8
-
8
+
9
9
  attr_reader :search_url, :counts_url
10
-
10
+
11
11
  #alias :total :total_entries
12
-
12
+
13
13
  def initialize(client)
14
14
  @search_url = "https://data-api.twitter.com/search/fullarchive/accounts/#{client.account}/#{client.label}.json"
15
15
  @counts_url = "https://data-api.twitter.com/search/fullarchive/accounts/#{client.account}/#{client.label}/counts.json"
16
16
  @auth = { username: client.username, password: client.password }
17
17
  end
18
-
18
+
19
19
  # Search using the full-archive search endpoint return an hash containing up to 500 results and the cursor to the next page
20
20
  # options[:query] query to twitter
21
21
  # options[:per_page] default is 500
@@ -28,7 +28,7 @@ module Gnip
28
28
  search_options[:maxResults] = options[:per_page]||500
29
29
  search_options[:fromDate] = Gnip.format_date(options[:date_from]) if options[:date_from]
30
30
  search_options[:toDate] = Gnip.format_date(options[:date_to]) if options[:date_to]
31
- search_options[:next] = options[:next_cursor] if options[:next_cursor]
31
+ search_options[:next] = options[:next_cursor] if options[:next_cursor]
32
32
  url = [self.search_url, search_options.to_query].join('?')
33
33
  begin
34
34
  gnip_call = self.class.get(url, basic_auth: @auth)
@@ -46,7 +46,7 @@ module Gnip
46
46
  end
47
47
  return response
48
48
  end
49
-
49
+
50
50
  # full aarchive search endpoints return total contents by day, minute, hour paginated
51
51
  # so to get totals across time period passed may need to run more than one call, the stop condition is cursor nil
52
52
  # bucket: must be one of [minute, hour, day]
@@ -60,7 +60,7 @@ module Gnip
60
60
  search_options[:next] = options[:next_cursor] if options[:next_cursor]
61
61
 
62
62
  url = [self.counts_url, search_options.to_query].join('?')
63
-
63
+
64
64
  begin
65
65
  gnip_call = self.class.get(url, basic_auth: @auth)
66
66
 
@@ -72,7 +72,7 @@ module Gnip
72
72
  if parsed_response[:error].present?
73
73
  response = { results: [], next: nil, error: parsed_response[:error][:message], code: gnip_call.response.code.to_i, calls: (response[:calls]||0) + 1 }
74
74
  else
75
- parsed_response[:results].each_with_index do |item, i|
75
+ parsed_response[:results].each_with_index do |item, i|
76
76
  parsed_response[:results][i] = item.merge(timePeriod: DateTime.parse(item[:timePeriod]).to_s)
77
77
  end
78
78
  response = { results: (response[:results]||[]) + parsed_response[:results], next: parsed_response[:next], code: gnip_call.response.code.to_i, calls: (response[:calls]||0) + 1 }
@@ -80,7 +80,9 @@ module Gnip
80
80
  rescue Exception => e
81
81
  response = { results: [], next: nil, error: e.message, code: 500 }
82
82
  end
83
- return response if !parsed_response[:next].to_s.present?
83
+ # If the next cursor is not present we fetched all the data
84
+ # It happens that twitter returns the same cursor, in that case we stop
85
+ return response if !parsed_response[:next].to_s.present? || (parsed_response[:next].to_s.present? && parsed_response[:next] == search_options[:next])
84
86
 
85
87
  total_by_time_period(query: search_options[:query],
86
88
  date_from: search_options[:fromDate],
@@ -89,7 +91,7 @@ module Gnip
89
91
  next_cursor: parsed_response[:next],
90
92
  response: response)
91
93
  end
92
-
94
+
93
95
  # return total contents in a specific date interval with a passed query
94
96
  def total(options={})
95
97
  extra = {}
@@ -97,8 +99,8 @@ module Gnip
97
99
  extra = { error: response[:error] } if response[:error].present?
98
100
  return { query: options[:query], total: response[:results].map{|item| item[:count]}.reduce(:+) }.merge!(extra)
99
101
  end
100
-
102
+
101
103
  end
102
-
104
+
103
105
  end
104
106
  end
@@ -1,3 +1,3 @@
1
1
  module Gnip
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnip-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duccio Giovannelli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler