gnip_api 1.2.2 → 1.2.3

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +24 -3
  3. data/README.md +70 -33
  4. data/Rakefile +7 -0
  5. data/doc/rdoc/classes/Gnip/Activity.html +354 -0
  6. data/doc/rdoc/classes/Gnip/Actor.html +300 -0
  7. data/doc/rdoc/classes/Gnip/GnipData.html +154 -0
  8. data/doc/rdoc/classes/Gnip/Message.html +236 -0
  9. data/doc/rdoc/classes/Gnip/SystemMessage.html +190 -0
  10. data/doc/rdoc/classes/Gnip/TwitterComplianceMessage.html +194 -0
  11. data/doc/rdoc/classes/Gnip/UndefinedMessage.html +83 -0
  12. data/doc/rdoc/classes/Gnip/Url.html +194 -0
  13. data/doc/rdoc/classes/Gnip.html +95 -0
  14. data/doc/rdoc/classes/GnipApi/Adapter.html +287 -0
  15. data/doc/rdoc/classes/GnipApi/Configuration.html +194 -0
  16. data/doc/rdoc/classes/GnipApi/Endpoints.html +191 -0
  17. data/doc/rdoc/classes/GnipApi/Errors/Adapter/GnipSoftwareError.html +83 -0
  18. data/doc/rdoc/classes/GnipApi/Errors/Adapter/RateLimitError.html +83 -0
  19. data/doc/rdoc/classes/GnipApi/Errors/Adapter/RequestError.html +56 -0
  20. data/doc/rdoc/classes/GnipApi/Errors/Adapter.html +66 -0
  21. data/doc/rdoc/classes/GnipApi/Errors/Configuration/InvalidOutputFormat.html +83 -0
  22. data/doc/rdoc/classes/GnipApi/Errors/Configuration.html +58 -0
  23. data/doc/rdoc/classes/GnipApi/Errors/JsonParser/ParseError.html +56 -0
  24. data/doc/rdoc/classes/GnipApi/Errors/JsonParser.html +64 -0
  25. data/doc/rdoc/classes/GnipApi/Errors/MissingAdapter.html +83 -0
  26. data/doc/rdoc/classes/GnipApi/Errors/MissingCredentials.html +83 -0
  27. data/doc/rdoc/classes/GnipApi/Errors/PowerTrack/MissingRules.html +83 -0
  28. data/doc/rdoc/classes/GnipApi/Errors/PowerTrack/StreamDown.html +56 -0
  29. data/doc/rdoc/classes/GnipApi/Errors/PowerTrack.html +65 -0
  30. data/doc/rdoc/classes/GnipApi/Errors/Search/MissingParameters.html +83 -0
  31. data/doc/rdoc/classes/GnipApi/Errors/Search.html +64 -0
  32. data/doc/rdoc/classes/GnipApi/Errors.html +79 -0
  33. data/doc/rdoc/classes/GnipApi/JsonParser.html +101 -0
  34. data/doc/rdoc/classes/GnipApi/PowerTrack/Buffer.html +237 -0
  35. data/doc/rdoc/classes/GnipApi/PowerTrack/Rule.html +196 -0
  36. data/doc/rdoc/classes/GnipApi/PowerTrack/Rules.html +188 -0
  37. data/doc/rdoc/classes/GnipApi/PowerTrack/Stream.html +359 -0
  38. data/doc/rdoc/classes/GnipApi/PowerTrack.html +73 -0
  39. data/doc/rdoc/classes/GnipApi/Request.html +216 -0
  40. data/doc/rdoc/classes/GnipApi/Response.html +232 -0
  41. data/doc/rdoc/classes/GnipApi/Search.html +101 -0
  42. data/doc/rdoc/classes/GnipApi.html +252 -0
  43. data/doc/rdoc/created.rid +24 -0
  44. data/doc/rdoc/css/style.css +343 -0
  45. data/doc/rdoc/files/LICENSE_txt.html +73 -0
  46. data/doc/rdoc/files/README_md.html +299 -0
  47. data/doc/rdoc/files/lib/gnip_api/adapter_rb.html +51 -0
  48. data/doc/rdoc/files/lib/gnip_api/configuration_rb.html +51 -0
  49. data/doc/rdoc/files/lib/gnip_api/endpoints_rb.html +51 -0
  50. data/doc/rdoc/files/lib/gnip_api/errors_rb.html +51 -0
  51. data/doc/rdoc/files/lib/gnip_api/gnip/activity_rb.html +51 -0
  52. data/doc/rdoc/files/lib/gnip_api/gnip/actor_rb.html +51 -0
  53. data/doc/rdoc/files/lib/gnip_api/gnip/gnip_data_rb.html +51 -0
  54. data/doc/rdoc/files/lib/gnip_api/gnip/message_rb.html +51 -0
  55. data/doc/rdoc/files/lib/gnip_api/gnip/system_message_rb.html +51 -0
  56. data/doc/rdoc/files/lib/gnip_api/gnip/twitter_compliance_message_rb.html +51 -0
  57. data/doc/rdoc/files/lib/gnip_api/gnip/url_rb.html +51 -0
  58. data/doc/rdoc/files/lib/gnip_api/json_parser_rb.html +51 -0
  59. data/doc/rdoc/files/lib/gnip_api/power_track/buffer_rb.html +51 -0
  60. data/doc/rdoc/files/lib/gnip_api/power_track/rule_rb.html +51 -0
  61. data/doc/rdoc/files/lib/gnip_api/power_track/rules_rb.html +55 -0
  62. data/doc/rdoc/files/lib/gnip_api/power_track/stream_rb.html +51 -0
  63. data/doc/rdoc/files/lib/gnip_api/request_rb.html +51 -0
  64. data/doc/rdoc/files/lib/gnip_api/response_rb.html +51 -0
  65. data/doc/rdoc/files/lib/gnip_api/search_rb.html +55 -0
  66. data/doc/rdoc/files/lib/gnip_api/version_rb.html +51 -0
  67. data/doc/rdoc/files/lib/gnip_api_rb.html +84 -0
  68. data/doc/rdoc/fr_class_index.html +92 -0
  69. data/doc/rdoc/fr_file_index.html +41 -0
  70. data/doc/rdoc/fr_method_index.html +4791 -0
  71. data/doc/rdoc/index.html +15 -0
  72. data/gnip_api.gemspec +3 -1
  73. data/lib/gnip_api/configuration.rb +18 -4
  74. data/lib/gnip_api/errors.rb +0 -1
  75. data/lib/gnip_api/power_track/buffer.rb +60 -14
  76. data/lib/gnip_api/power_track/stream.rb +52 -17
  77. data/lib/gnip_api/response.rb +3 -2
  78. data/lib/gnip_api/version.rb +1 -1
  79. data/spec/gnip_api/power_track/buffer_spec.rb +8 -0
  80. data/spec/gnip_api/response_spec.rb +16 -0
  81. data/spec/spec_helper.rb +1 -0
  82. metadata +97 -2
@@ -0,0 +1,299 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>README.md</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../css/style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ function popupCode(url) {
9
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
10
+ }
11
+
12
+ function toggleCode(id) {
13
+ var code = document.getElementById(id)
14
+
15
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
16
+ return true
17
+ }
18
+
19
+ // Make codeblocks hidden by default
20
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
21
+ </script>
22
+ </head>
23
+ <body class='page'>
24
+ <div class='file' id='wrapper'>
25
+ <div class='header'>
26
+ <h1 class='name'>README.md
27
+ </h1>
28
+ <div class='paths'>
29
+ README.md
30
+ </div>
31
+ <div class='last-update'>
32
+ Last Update:
33
+ <span class='datetime'>2017-09-07 18:27:35 -0300</span>
34
+ </div>
35
+ </div>
36
+ <div id='content'>
37
+ <div id='text'>
38
+ <div id='description'>
39
+ <h1 id="label-GnipApi"><a href="../classes/GnipApi.html">GnipApi</a><span><a href="#label-GnipApi">&para;</a> <a href="#top">&uarr;</a></span></h1>
40
+
41
+ <p>Connect with different <a href="../classes/Gnip.html">Gnip</a> APIs and get
42
+ data from streams. Currently Full Archive Search and PowerTrack APIs for
43
+ Twitter data are implemented.</p>
44
+
45
+ <p>Documentation about <a href="../classes/Gnip.html">Gnip</a> APIs can be
46
+ found <a target="_top" href="http://support.gnip.com/">here</a>.</p>
47
+
48
+ <p><a href="../classes/Gnip.html">Gnip</a> API status page can be found <a
49
+ href="https://status.gnip.com/">here</a></p>
50
+
51
+ <h2 id="label-What+is+Gnip-3F">What is <a href="../classes/Gnip.html">Gnip</a>?<span><a href="#label-What+is+Gnip-3F">&para;</a> <a href="#top">&uarr;</a></span></h2>
52
+
53
+ <p>A Twitter division that offers access to Twitter data both historically and
54
+ in real time. <a href="../classes/Gnip.html">Gnip</a> is not restricted to
55
+ Twitter only though, it offers a set of different data sources you can
56
+ integrate, Twitter is their main one of course.</p>
57
+
58
+ <h1 id="label-Gnip+APIs"><a href="../classes/Gnip.html">Gnip</a> APIs<span><a href="#label-Gnip+APIs">&para;</a> <a href="#top">&uarr;</a></span></h1>
59
+
60
+ <h2 id="label-Full+Archive+Search">Full Archive Search<span><a href="#label-Full+Archive+Search">&para;</a> <a href="#top">&uarr;</a></span></h2>
61
+
62
+ <p>It provides historical data with some aggregiations and can fetch both
63
+ activities and counts over a period of time. There are some limitations so
64
+ be sure to check the documentation.</p>
65
+
66
+ <p>Search API could return a 503 Software Error, which to me is just a
67
+ different way of a 500 error. Usually this happens on specific situations
68
+ with specific queries, however, it&#39;s not repeatable 100% of the time.
69
+ If you encounter this error, make your script wait for some seconds and
70
+ retry. Alternatively you can break down further the rules you&#39;re using
71
+ or the periods. As far as I&#39;m aware of, it&#39;s likely to happen when
72
+ querying large amounts of data on wide periods.</p>
73
+
74
+ <h2 id="label-PowerTrack">PowerTrack<span><a href="#label-PowerTrack">&para;</a> <a href="#top">&uarr;</a></span></h2>
75
+
76
+ <p>Provides ways to setup rules that act as filters/matchers and an HTTP
77
+ stream endpoint that will send the results to the consumer.</p>
78
+
79
+ <p>The HTTP stream can suffer from unexpected connection loss. Sometimes
80
+ it&#39;s intended from <a href="../classes/Gnip.html">Gnip</a>, and
81
+ sometimes it doesn&#39;t seem so. Depending on what you&#39;re doing with
82
+ the received data, you may be disconnected due to a slow consumer. Ideally
83
+ you shouldn&#39;t do anything else than read and do processing on a
84
+ different process/thread. <a href="../classes/GnipApi.html">GnipApi</a>
85
+ offers a few different methods to deal with this.</p>
86
+
87
+ <h2 id="label-A+word+about+rules">A word about rules<span><a href="#label-A+word+about+rules">&para;</a> <a href="#top">&uarr;</a></span></h2>
88
+
89
+ <p>It can be tricky to define proper rules. Please read the documentation on
90
+ each APIs to know how rules work. Search API and PowerTrack both use
91
+ similar rule structure, but there are differences between what can each do.</p>
92
+
93
+ <p>In some cases a rule can match undesired information. This is because <a
94
+ href="../classes/Gnip.html">Gnip</a> tokenizes the data and applies the
95
+ rules to that parsed data. For example, URLs can be matched by accident,
96
+ and it won&#39;t be clear why exaclty. <a
97
+ href="../classes/Gnip.html">Gnip</a> doesn&#39;t mention what fields of a
98
+ source object is considering to match so be sure to target the matching
99
+ properly.</p>
100
+
101
+ <h1 id="label-Installation">Installation<span><a href="#label-Installation">&para;</a> <a href="#top">&uarr;</a></span></h1>
102
+
103
+ <p>Add this line to your application&#39;s Gemfile:</p>
104
+
105
+ <pre class="ruby"><span class="ruby-identifier">gem</span> <span class="ruby-string">&#39;gnip_api&#39;</span></pre>
106
+
107
+ <p>And then execute:</p>
108
+
109
+ <pre>$ bundle</pre>
110
+
111
+ <p>Or install it yourself as:</p>
112
+
113
+ <pre>$ gem install gnip_api</pre>
114
+
115
+ <p>Use the master branch to get more frequent updates on this gem.</p>
116
+
117
+ <h1 id="label-Usage">Usage<span><a href="#label-Usage">&para;</a> <a href="#top">&uarr;</a></span></h1>
118
+
119
+ <h2 id="label-Configure+the+gem">Configure the gem<span><a href="#label-Configure+the+gem">&para;</a> <a href="#top">&uarr;</a></span></h2>
120
+
121
+ <pre class="ruby"><span class="ruby-constant">GnipApi</span>.<span class="ruby-identifier">configure</span> <span class="ruby-operator">|</span><span class="ruby-identifier">config</span><span class="ruby-operator">|</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">user</span> = <span class="ruby-string">&#39;someone&#39;</span> <span class="ruby-comment"># Gnip Account Username</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">password</span> = <span class="ruby-string">&#39;something&#39;</span> <span class="ruby-comment"># Gnip Password</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">account</span> = <span class="ruby-string">&#39;myGnipAccount&#39;</span> <span class="ruby-comment"># Your accounts name</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">logger</span> = <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;myLog.log&#39;</span>) <span class="ruby-comment"># You can also provide a custom logger</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">source</span> = <span class="ruby-string">&#39;twitter&#39;</span> <span class="ruby-comment"># General source, if none defined when quering, this will be used</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">label</span> = <span class="ruby-string">&#39;mystream&#39;</span> <span class="ruby-comment"># General stream label, if none defined when quering, this will be used</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">request_timeout</span> = <span class="ruby-value">120</span> <span class="ruby-comment"># Default time out on all requests, defaults to 60</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">debug</span> = <span class="ruby-keyword">false</span> <span class="ruby-comment"># Defaults to false, enables/disables debug output on log</span>&#x000A; <span class="ruby-identifier">config</span>.<span class="ruby-identifier">log_level</span> = <span class="ruby-constant">Logger</span><span class="ruby-operator">::</span><span class="ruby-constant">WARN</span> <span class="ruby-comment"># Set it to Logger::DEBUG if you have problems to inspect queries and data</span>&#x000A;<span class="ruby-keyword">end</span></pre>
122
+
123
+ <p>Put the avobe code in an initializer if you&#39;re using Rails, or
124
+ somewhere else if you aren&#39;t. After that you can interact with <a
125
+ href="../classes/Gnip.html">Gnip</a> APIs.</p>
126
+
127
+ <p>Note that you&#39;ll need a source and a label. Source is the data source
128
+ within <a href="../classes/Gnip.html">Gnip</a>, such as Twitter, and label
129
+ is the identifier of your stream.</p>
130
+
131
+ <h2 id="label-Search+API">Search API<span><a href="#label-Search+API">&para;</a> <a href="#top">&uarr;</a></span></h2>
132
+
133
+ <h3 id="label-Some+notes">Some notes<span><a href="#label-Some+notes">&para;</a> <a href="#top">&uarr;</a></span></h3>
134
+
135
+ <p>While using the Full Archive Search or FAS as we call it we faced some
136
+ issues that you may encounter as well if you use it. The most notorious one
137
+ is the 503 “You encountered a problem in our software” which is mentioned
138
+ avobe. Upon troubleshooting this error, the client side “solution” or
139
+ workaround to better put it, is to iterate from the client the period.
140
+ Instead of letting GNIP paginate the data build smaller periods of time.
141
+ For example, instead of requesting from year 2016 to 2017, do 12 requests
142
+ of 1 month each. We found that making this period size smaller and smaller
143
+ ends up making it work. A higher process built using this gem splits any
144
+ given period in smaller ones and iterates over the data, re running missing
145
+ periods split further to fill in missing data. The smalles period that
146
+ seems to have 100% chances of success is 1 hour. If you wonder who came up
147
+ with this ugly solution, the answer is GNIP itself, upon talking to their
148
+ support area about this. It doesn&#39;t seem proper to include this on the
149
+ gem since this errors is not supposed to happen, but it may eventually be
150
+ included as an alternative querying to mitigate the problem.</p>
151
+
152
+ <h3 id="label-Overview">Overview<span><a href="#label-Overview">&para;</a> <a href="#top">&uarr;</a></span></h3>
153
+
154
+ <p>The Search API allows you to get counts or activities in a time period,
155
+ with a maximum period size of 30 days per request. PowerTrack rules are
156
+ used as query parameter, but be careful <strong>PowerTrack operators may
157
+ not be supported on Search API or could behave differently</strong>. Read
158
+ the <a href="../classes/Gnip.html">Gnip</a> docs to make sure. To access
159
+ the Search API you will need a rule first, you can use PowerTrack Rule
160
+ object for it:</p>
161
+
162
+ <pre class="ruby"><span class="ruby-identifier">rule</span> = <span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">PowerTrack</span><span class="ruby-operator">::</span><span class="ruby-constant">Rule</span>.<span class="ruby-identifier">new</span> :<span class="ruby-identifier">value</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;keyword1 OR keyword2&#39;</span></pre>
163
+
164
+ <p>Then you can query the search endpoint to get counts or activities. For
165
+ counts:</p>
166
+
167
+ <pre class="ruby"><span class="ruby-identifier">results</span> = <span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">Search</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">counts</span> :<span class="ruby-identifier">rule</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">rule</span></pre>
168
+
169
+ <p>For activities:</p>
170
+
171
+ <pre class="ruby"><span class="ruby-identifier">results</span> = <span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">Search</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">activities</span> :<span class="ruby-identifier">rule</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">rule</span></pre>
172
+
173
+ <p>Responses are parsed, so you can then use the output normally as any other
174
+ Ruby object. For the case of activities, they get converted to <a
175
+ href="../classes/Gnip/Activity.html">Gnip::Activity</a> objects, and have
176
+ all the rest parsed as they would came from stream.</p>
177
+
178
+ <p>You can set different parameters:</p>
179
+
180
+ <pre class="ruby"><span class="ruby-identifier">results</span> = <span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">Search</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">counts</span> :<span class="ruby-identifier">rule</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">rule</span>, :<span class="ruby-identifier">from_date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&#39;2016-01-01 00:00&#39;</span>), :<span class="ruby-identifier">to_date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&#39;2016-05-01 22:00&#39;</span>), :<span class="ruby-identifier">bucket</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;day&#39;</span></pre>
181
+
182
+ <p>For activities, there are a few extra considerations:</p>
183
+ <ul><li>
184
+ <p>A param <code>:max_results</code> indicates how many activities to return
185
+ on a response, valid values are from 10 to 500, default is 100, this param
186
+ does not work on counts.</p>
187
+ </li><li>
188
+ <p>As you noticed, you pass a <code>GnipApi::PowerTrack::Rule</code> object to
189
+ the search endpoint, and as you may also know, these objects have mostly 2
190
+ things: value (actual rule), and tag. When querying activities on the
191
+ Search API, you can optionally use a tag that is returned on the activity,
192
+ along with the rule. This tag is deduced from the rule object you pass, in
193
+ other words, if you want a tag, add it on the
194
+ <code>GnipApi::PowerTrack::Rule</code> object, it&#39;s not a valid param
195
+ for the method.</p>
196
+ </li><li>
197
+ <p>The <code>:bucket</code> option is only for counts.</p>
198
+ </li></ul>
199
+
200
+ <p>When you query for more than 30 days or more activities than
201
+ <code>:max_results</code>, the results will include a <code>:next</code>
202
+ token to iterate over the remaining pages. You can instantly feed this
203
+ token to a following request with same parameters:</p>
204
+
205
+ <pre class="ruby"><span class="ruby-identifier">results</span> = <span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">Search</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">counts</span> :<span class="ruby-identifier">rule</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">rule</span>, :<span class="ruby-identifier">from_date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&#39;2016-01-01 00:00&#39;</span>), :<span class="ruby-identifier">to_date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&#39;2016-05-01 22:00&#39;</span>), :<span class="ruby-identifier">bucket</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;day&#39;</span>, :<span class="ruby-identifier">next_token</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;token_from_previous_request&#39;</span></pre>
206
+
207
+ <h2 id="label-PowerTrack">PowerTrack<span><a href="#label-PowerTrack">&para;</a> <a href="#top">&uarr;</a></span></h2>
208
+
209
+ <p>PowerTrack API has various functions. You can upload, delete and get rules
210
+ and you can stream the activities. To create rules you need to create the
211
+ rule objects:</p>
212
+
213
+ <pre class="ruby"><span class="ruby-identifier">rules</span> = [] &#x000A;<span class="ruby-identifier">rules</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">PowerTrack</span><span class="ruby-operator">::</span><span class="ruby-constant">Rule</span>.<span class="ruby-identifier">new</span> :<span class="ruby-identifier">value</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;keyword1 OR keyword2&#39;</span>, :<span class="ruby-identifier">tag</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;first_rule&#39;</span>&#x000A;<span class="ruby-identifier">rules</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">PowerTrack</span><span class="ruby-operator">::</span><span class="ruby-constant">Rule</span>.<span class="ruby-identifier">new</span> :<span class="ruby-identifier">value</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;keyword3 keyword4&#39;</span>, :<span class="ruby-identifier">tag</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&#39;second_rule&#39;</span></pre>
214
+
215
+ <p>Once you have your rule objects set, you can put them into an array and
216
+ feed them to the PowerTrack Rules API:</p>
217
+
218
+ <pre class="ruby"><span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">PowerTrack</span><span class="ruby-operator">::</span><span class="ruby-constant">Rules</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">create</span> <span class="ruby-identifier">rules</span></pre>
219
+
220
+ <p>That will upload the rules to the stream. The endpoint doesn&#39;t return
221
+ anything on success but it will validate rules before applying and any
222
+ syntax error will be raised as an error.</p>
223
+
224
+ <p>To get a list of rules defined in the stream:</p>
225
+
226
+ <pre class="ruby"><span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">PowerTrack</span><span class="ruby-operator">::</span><span class="ruby-constant">Rules</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">list</span></pre>
227
+
228
+ <p>That will return an array of GnipRule::PowerTrack::Rule objects. In the
229
+ same way as the upload the delete method removes 1 or more rules:</p>
230
+
231
+ <pre class="ruby"><span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">PowerTrack</span><span class="ruby-operator">::</span><span class="ruby-constant">Rules</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">rules</span></pre>
232
+
233
+ <p>Same as upload, no response from <a href="../classes/Gnip.html">Gnip</a>
234
+ when deleting. <strong>Important</strong>: There&#39;s no mapping between
235
+ PowerTrack Rules and the rules you create, and they do not generate any
236
+ identifier. <a href="../classes/Gnip.html">Gnip</a> suggests to generate an
237
+ UID including the tag, to create an identifier and keep the mapping. When
238
+ you delete a rule, the rule you are sending <strong>needs to be exaclty the
239
+ same you used on upload</strong>, otherwise you would be trying to delete a
240
+ non-existent rule or deleting a different rule, both cases without error
241
+ from <a href="../classes/Gnip.html">Gnip</a> alerting this. Running a hash
242
+ function over the JSON rule should do the trick.</p>
243
+
244
+ <p>Finally, you can stream the activities and do something with them:</p>
245
+
246
+ <pre class="ruby"><span class="ruby-constant">GnipApi</span><span class="ruby-operator">::</span><span class="ruby-constant">PowerTrack</span><span class="ruby-operator">::</span><span class="ruby-constant">Stream</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">consume</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">messages</span><span class="ruby-operator">|</span>&#x000A; <span class="ruby-identifier">messages</span>.<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">activity?</span>}.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">body</span>}&#x000A; <span class="ruby-identifier">messages</span>.<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">system_message?</span>}.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">message</span>}&#x000A;<span class="ruby-keyword">end</span></pre>
247
+
248
+ <h1 id="label-Documentation">Documentation<span><a href="#label-Documentation">&para;</a> <a href="#top">&uarr;</a></span></h1>
249
+
250
+ <p>RDoc was integrated for this gem and documents will be included in the repo
251
+ to browse. You can execute:</p>
252
+
253
+ <pre>$ rake rdoc</pre>
254
+
255
+ <p>To regenerate it. Browse doc/rdoc/index.html to inspect the bundled
256
+ documentation.</p>
257
+
258
+ <h1 id="label-WIP+State">WIP State<span><a href="#label-WIP+State">&para;</a> <a href="#top">&uarr;</a></span></h1>
259
+
260
+ <p>Various <a href="../classes/Gnip.html">Gnip</a> features aren&#39;t
261
+ implemented yet and I lack access to them. I could implement them from
262
+ documentation alone, but given the experience I have with <a
263
+ href="../classes/Gnip.html">Gnip</a>, it might not work at all.</p>
264
+
265
+ <h1 id="label-Contributing">Contributing<span><a href="#label-Contributing">&para;</a> <a href="#top">&uarr;</a></span></h1>
266
+ <ol><li>
267
+ <p>Fork it ( <a
268
+ href="https://github.com/[my-github-username]/gnip_api/fork">github.com/[my-github-username]/gnip_api/fork</a>
269
+ )</p>
270
+ </li><li>
271
+ <p>Create your feature branch (<code>git checkout -b my-new-feature</code>)</p>
272
+ </li><li>
273
+ <p>Commit your changes (<code>git commit -am &#39;Add some&#x000A;feature&#39;</code>)</p>
274
+ </li><li>
275
+ <p>Push to the branch (<code>git push origin my-new-feature</code>)</p>
276
+ </li><li>
277
+ <p>Create a new Pull Request</p>
278
+ </li></ol>
279
+
280
+ <p>Feel free to ask/suggest ideas or features, or to report any bugs or
281
+ issues.</p>
282
+
283
+ <p>This library was constructed with the help of <a
284
+ href="https://github.com/antico5">Armando Andini</a> who provided the basis
285
+ to connect with the <a href="../classes/Gnip.html">Gnip</a> APIs.</p>
286
+ </div>
287
+ <div id='context'>
288
+ </div>
289
+
290
+ </div>
291
+ </div>
292
+
293
+ <div id='footer-push'></div>
294
+ </div>
295
+ <div id='footer'>
296
+ <a href="https://github.com/rdoc/hanna-nouveau"><strong>Hanna Nouveau</strong> RDoc template</a>
297
+ </div>
298
+ </body>
299
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>adapter.rb</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ function popupCode(url) {
9
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
10
+ }
11
+
12
+ function toggleCode(id) {
13
+ var code = document.getElementById(id)
14
+
15
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
16
+ return true
17
+ }
18
+
19
+ // Make codeblocks hidden by default
20
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
21
+ </script>
22
+ </head>
23
+ <body class='page'>
24
+ <div class='file' id='wrapper'>
25
+ <div class='header'>
26
+ <h1 class='name'>adapter.rb
27
+ </h1>
28
+ <div class='paths'>
29
+ lib/gnip_api/adapter.rb
30
+ </div>
31
+ <div class='last-update'>
32
+ Last Update:
33
+ <span class='datetime'>2017-08-11 14:16:14 -0300</span>
34
+ </div>
35
+ </div>
36
+ <div id='content'>
37
+ <div id='text'>
38
+ <div id='description'></div>
39
+ <div id='context'>
40
+ </div>
41
+
42
+ </div>
43
+ </div>
44
+
45
+ <div id='footer-push'></div>
46
+ </div>
47
+ <div id='footer'>
48
+ <a href="https://github.com/rdoc/hanna-nouveau"><strong>Hanna Nouveau</strong> RDoc template</a>
49
+ </div>
50
+ </body>
51
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>configuration.rb</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ function popupCode(url) {
9
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
10
+ }
11
+
12
+ function toggleCode(id) {
13
+ var code = document.getElementById(id)
14
+
15
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
16
+ return true
17
+ }
18
+
19
+ // Make codeblocks hidden by default
20
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
21
+ </script>
22
+ </head>
23
+ <body class='page'>
24
+ <div class='file' id='wrapper'>
25
+ <div class='header'>
26
+ <h1 class='name'>configuration.rb
27
+ </h1>
28
+ <div class='paths'>
29
+ lib/gnip_api/configuration.rb
30
+ </div>
31
+ <div class='last-update'>
32
+ Last Update:
33
+ <span class='datetime'>2017-09-07 17:02:34 -0300</span>
34
+ </div>
35
+ </div>
36
+ <div id='content'>
37
+ <div id='text'>
38
+ <div id='description'></div>
39
+ <div id='context'>
40
+ </div>
41
+
42
+ </div>
43
+ </div>
44
+
45
+ <div id='footer-push'></div>
46
+ </div>
47
+ <div id='footer'>
48
+ <a href="https://github.com/rdoc/hanna-nouveau"><strong>Hanna Nouveau</strong> RDoc template</a>
49
+ </div>
50
+ </body>
51
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>endpoints.rb</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ function popupCode(url) {
9
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
10
+ }
11
+
12
+ function toggleCode(id) {
13
+ var code = document.getElementById(id)
14
+
15
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
16
+ return true
17
+ }
18
+
19
+ // Make codeblocks hidden by default
20
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
21
+ </script>
22
+ </head>
23
+ <body class='page'>
24
+ <div class='file' id='wrapper'>
25
+ <div class='header'>
26
+ <h1 class='name'>endpoints.rb
27
+ </h1>
28
+ <div class='paths'>
29
+ lib/gnip_api/endpoints.rb
30
+ </div>
31
+ <div class='last-update'>
32
+ Last Update:
33
+ <span class='datetime'>2017-08-10 13:57:52 -0300</span>
34
+ </div>
35
+ </div>
36
+ <div id='content'>
37
+ <div id='text'>
38
+ <div id='description'></div>
39
+ <div id='context'>
40
+ </div>
41
+
42
+ </div>
43
+ </div>
44
+
45
+ <div id='footer-push'></div>
46
+ </div>
47
+ <div id='footer'>
48
+ <a href="https://github.com/rdoc/hanna-nouveau"><strong>Hanna Nouveau</strong> RDoc template</a>
49
+ </div>
50
+ </body>
51
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>errors.rb</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ function popupCode(url) {
9
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
10
+ }
11
+
12
+ function toggleCode(id) {
13
+ var code = document.getElementById(id)
14
+
15
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
16
+ return true
17
+ }
18
+
19
+ // Make codeblocks hidden by default
20
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
21
+ </script>
22
+ </head>
23
+ <body class='page'>
24
+ <div class='file' id='wrapper'>
25
+ <div class='header'>
26
+ <h1 class='name'>errors.rb
27
+ </h1>
28
+ <div class='paths'>
29
+ lib/gnip_api/errors.rb
30
+ </div>
31
+ <div class='last-update'>
32
+ Last Update:
33
+ <span class='datetime'>2017-09-07 18:30:14 -0300</span>
34
+ </div>
35
+ </div>
36
+ <div id='content'>
37
+ <div id='text'>
38
+ <div id='description'></div>
39
+ <div id='context'>
40
+ </div>
41
+
42
+ </div>
43
+ </div>
44
+
45
+ <div id='footer-push'></div>
46
+ </div>
47
+ <div id='footer'>
48
+ <a href="https://github.com/rdoc/hanna-nouveau"><strong>Hanna Nouveau</strong> RDoc template</a>
49
+ </div>
50
+ </body>
51
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>activity.rb</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ function popupCode(url) {
9
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
10
+ }
11
+
12
+ function toggleCode(id) {
13
+ var code = document.getElementById(id)
14
+
15
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
16
+ return true
17
+ }
18
+
19
+ // Make codeblocks hidden by default
20
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
21
+ </script>
22
+ </head>
23
+ <body class='page'>
24
+ <div class='file' id='wrapper'>
25
+ <div class='header'>
26
+ <h1 class='name'>activity.rb
27
+ </h1>
28
+ <div class='paths'>
29
+ lib/gnip_api/gnip/activity.rb
30
+ </div>
31
+ <div class='last-update'>
32
+ Last Update:
33
+ <span class='datetime'>2017-07-14 15:08:05 -0300</span>
34
+ </div>
35
+ </div>
36
+ <div id='content'>
37
+ <div id='text'>
38
+ <div id='description'></div>
39
+ <div id='context'>
40
+ </div>
41
+
42
+ </div>
43
+ </div>
44
+
45
+ <div id='footer-push'></div>
46
+ </div>
47
+ <div id='footer'>
48
+ <a href="https://github.com/rdoc/hanna-nouveau"><strong>Hanna Nouveau</strong> RDoc template</a>
49
+ </div>
50
+ </body>
51
+ </html>
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>actor.rb</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../../../../css/style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ function popupCode(url) {
9
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
10
+ }
11
+
12
+ function toggleCode(id) {
13
+ var code = document.getElementById(id)
14
+
15
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
16
+ return true
17
+ }
18
+
19
+ // Make codeblocks hidden by default
20
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
21
+ </script>
22
+ </head>
23
+ <body class='page'>
24
+ <div class='file' id='wrapper'>
25
+ <div class='header'>
26
+ <h1 class='name'>actor.rb
27
+ </h1>
28
+ <div class='paths'>
29
+ lib/gnip_api/gnip/actor.rb
30
+ </div>
31
+ <div class='last-update'>
32
+ Last Update:
33
+ <span class='datetime'>2016-10-24 16:03:33 -0300</span>
34
+ </div>
35
+ </div>
36
+ <div id='content'>
37
+ <div id='text'>
38
+ <div id='description'></div>
39
+ <div id='context'>
40
+ </div>
41
+
42
+ </div>
43
+ </div>
44
+
45
+ <div id='footer-push'></div>
46
+ </div>
47
+ <div id='footer'>
48
+ <a href="https://github.com/rdoc/hanna-nouveau"><strong>Hanna Nouveau</strong> RDoc template</a>
49
+ </div>
50
+ </body>
51
+ </html>