galerts 0.0.3 → 0.0.4
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/README.md +18 -4
- data/galerts.gemspec +1 -1
- data/lib/galerts.rb +1 -0
- data/lib/galerts/manager.rb +63 -4
- data/lib/galerts/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26904b73f6a9f04d400c0c54400e92ac705966bb
|
4
|
+
data.tar.gz: 98cf2bdd647e1823bf82713b3e040d0b55ae2128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5cbdc60b90323b07018febbc9fce0d4aa0708ecfa8fe51ff2485caeaae0edc9cfa1e877a0a10178e6444e4d9f93312cf61e25b2782e8b2dd6e6886a52137e0a
|
7
|
+
data.tar.gz: 104e3d013cf7dd87acef77367a216535c43b2b0effe757efbaccf51efafa78a9eaef20214fc5edcb17362e26208735f44b43b378fb28917a305a4e166d642db6
|
data/README.md
CHANGED
@@ -7,9 +7,16 @@ alerts webpage.
|
|
7
7
|
|
8
8
|
- List all alerts associated with account.
|
9
9
|
- Create new alert for any google domain.
|
10
|
-
-
|
10
|
+
- Update existing alert.
|
11
|
+
- Delete an alert.
|
11
12
|
- Find alerts by query, id, data_id, feed_url, domain, language, how_many,
|
12
|
-
region, delivery
|
13
|
+
region, delivery.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
```sh
|
18
|
+
gem install galerts
|
19
|
+
```
|
13
20
|
|
14
21
|
## Example
|
15
22
|
|
@@ -34,13 +41,20 @@ manager.create("my keywords", {
|
|
34
41
|
}
|
35
42
|
)
|
36
43
|
|
37
|
-
|
38
|
-
|
44
|
+
alert = manager.alerts.last
|
45
|
+
|
46
|
+
# Update the query of this alert
|
47
|
+
alert.query = "updated keyword"
|
48
|
+
manager.update(alert)
|
39
49
|
|
40
50
|
# Find examples
|
41
51
|
manager.find_by_query("keyword")
|
42
52
|
manager.find_by_delivery(Galerts::RSS)
|
43
53
|
manager.find({query: "keyword", delivery: Galerts::RSS})
|
54
|
+
|
55
|
+
# Delete an alert with alerts data_id
|
56
|
+
manager.delete("alerts data_id")
|
57
|
+
|
44
58
|
```
|
45
59
|
|
46
60
|
## Contribute
|
data/galerts.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.version = Galerts::VERSION.dup
|
6
6
|
s.date = '2014-09-16'
|
7
7
|
s.summary = 'Ruby library to manage google alerts'
|
8
|
-
s.description = %q{
|
8
|
+
s.description = %q{Ruby library to manage google alerts}
|
9
9
|
s.authors = ["Emre Can Yılmaz"]
|
10
10
|
s.email = ['emrecan@ecylmz.com']
|
11
11
|
s.files = `git ls-files`.split("\n")
|
data/lib/galerts.rb
CHANGED
@@ -2,6 +2,7 @@ module Galerts
|
|
2
2
|
# URLs
|
3
3
|
CREATE_ALERT_URL = 'https://www.google.com/alerts/create?'
|
4
4
|
DELETE_ALERT_URL = 'https://www.google.com/alerts/delete?'
|
5
|
+
MODIFY_ALERT_URL = 'https://www.google.com/alerts/modify?'
|
5
6
|
GOOGLE_LOGIN_URL = 'https://accounts.google.com/ServiceLogin?'
|
6
7
|
ALERTS_URL = 'https://www.google.com/alerts'
|
7
8
|
LOGIN_URL = "#{GOOGLE_LOGIN_URL}service=alerts&continue=#{ALERTS_URL}"
|
data/lib/galerts/manager.rb
CHANGED
@@ -83,7 +83,7 @@ module Galerts
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
86
|
+
def build_update_params(alert)
|
87
87
|
# set delivery and frequency parameters
|
88
88
|
if alert.delivery == EMAIL
|
89
89
|
if alert.frequency == DAILY
|
@@ -110,17 +110,56 @@ module Galerts
|
|
110
110
|
|
111
111
|
# TODO: need more readable
|
112
112
|
params = {
|
113
|
-
'params' => "[null,[null,null,
|
113
|
+
'params' => "[null,[null,null,[null,\"#{alert.query}\",\"#{alert.domain}\",[null,\"#{alert.language}\",\"#{alert.region}\"],null,null,null,#{alert.region == "" ? 1 : 0},1],#{sources_text},#{HOW_MANY_TYPES[alert.how_many]},[[null,#{delivery_and_frequency},\"#{alert.language + '-' + alert.region.upcase}\",null,null,null,null,null,'0']]]]"
|
114
114
|
}
|
115
115
|
|
116
116
|
params = URI.encode_www_form(params)
|
117
117
|
end
|
118
118
|
|
119
|
+
def build_params(alert, action)
|
120
|
+
# set delivery and frequency parameters
|
121
|
+
if alert.delivery == EMAIL
|
122
|
+
if alert.frequency == DAILY
|
123
|
+
delivery_and_frequency = "#{DELIVERY_TYPES[EMAIL]},\"#{@email}\",[null,null,11],#{FREQ_TYPES[DAILY]}"
|
124
|
+
elsif alert.frequency == WEEKLY
|
125
|
+
delivery_and_frequency = "#{DELIVERY_TYPES[EMAIL]},\"#{@email}\",[null,null,11,1],#{FREQ_TYPES[WEEKLY]}"
|
126
|
+
elsif alert.frequency == RT
|
127
|
+
delivery_and_frequency = "#{DELIVERY_TYPES[EMAIL]},\"#{@email}\",[],#{FREQ_TYPES[RT]}"
|
128
|
+
end
|
129
|
+
elsif alert.delivery == RSS
|
130
|
+
delivery_and_frequency = "#{DELIVERY_TYPES[RSS]},\"\",[],#{FREQ_TYPES[RT]}"
|
131
|
+
end
|
132
|
+
|
133
|
+
if alert.sources.empty?
|
134
|
+
sources_text = 'null'
|
135
|
+
else
|
136
|
+
sources_text = "["
|
137
|
+
alert.sources.collect do |source|
|
138
|
+
raise "Unknown alert source" unless SOURCES_TYPES.has_key?(source)
|
139
|
+
sources_text += SOURCES_TYPES[source].to_s + ','
|
140
|
+
end
|
141
|
+
sources_text = sources_text.chop + ']'
|
142
|
+
end
|
143
|
+
|
144
|
+
# TODO: need more readable
|
145
|
+
if action == 0 # create
|
146
|
+
params = {
|
147
|
+
'params' => "[null,[null,null,null,[null,\"#{alert.query}\",\"#{alert.domain}\",[null,\"#{alert.language}\",\"#{alert.region}\"],null,null,null,#{alert.region == "" ? 1 : 0},1],#{sources_text},#{HOW_MANY_TYPES[alert.how_many]},[[null,#{delivery_and_frequency},\"#{alert.language + '-' + alert.region.upcase}\",null,null,null,null,null,'0']]]]"
|
148
|
+
}
|
149
|
+
return URI.encode_www_form(params)
|
150
|
+
elsif action == 1 # edit
|
151
|
+
params = {
|
152
|
+
'params' => "[null,\"#{alert.data_id}\",[null,null,null,[null,\"#{alert.query}\",\"#{alert.domain}\",[null,\"#{alert.language}\",\"#{alert.region}\"],null,null,null,#{alert.region == "" ? 1 : 0},1],#{sources_text},#{HOW_MANY_TYPES[alert.how_many]},[[null,#{delivery_and_frequency},\"#{alert.language + '-' + alert.region.upcase}\",null,null,null,null,null,\"#{alert.id}\"]]]]"
|
153
|
+
}
|
154
|
+
return URI.encode_www_form(params)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
119
158
|
def create(query, options = {})
|
120
159
|
alert = Alert.new(query, options)
|
121
160
|
|
122
161
|
x = alerts_page.css('div#gb-main div.main-page script').text.split(',').last[1..-4]
|
123
|
-
response = @agent.post("#{CREATE_ALERT_URL}x=#{x}",
|
162
|
+
response = @agent.post("#{CREATE_ALERT_URL}x=#{x}", build_params(alert, 0), {'Content-Type' => 'application/x-www-form-urlencoded'})
|
124
163
|
|
125
164
|
if response.body == ALERT_EXIST
|
126
165
|
raise "Alert exist!"
|
@@ -139,11 +178,31 @@ module Galerts
|
|
139
178
|
end
|
140
179
|
end
|
141
180
|
|
181
|
+
def update(alert)
|
182
|
+
x = alerts_page.css('div#gb-main div.main-page script').text.split(',').last[1..-4]
|
183
|
+
response = @agent.post("#{MODIFY_ALERT_URL}x=#{x}", build_params(alert, 1), {'Content-Type' => 'application/x-www-form-urlencoded'})
|
184
|
+
|
185
|
+
if response.body == ALERT_EXIST
|
186
|
+
raise "Alert exist!"
|
187
|
+
elsif response.body == ALERT_SOMETHING_WENT_WRONG
|
188
|
+
raise "Something went wrong!" # internal error, html changed maybe
|
189
|
+
else
|
190
|
+
response_body = response.body.gsub('null', 'nil')
|
191
|
+
created_alert = Nokogiri::HTML(eval(response_body)[4][0][2], nil, 'utf-8')
|
192
|
+
|
193
|
+
if alert.delivery == RSS
|
194
|
+
alert.id = created_alert.css('a')[0]['href'].split('/').last if alert.delivery == RSS
|
195
|
+
alert.feed_url = created_alert.css('a')[0]['href']
|
196
|
+
end
|
197
|
+
alert.data_id = created_alert.css('li')[0]['data-id']
|
198
|
+
alert
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
142
202
|
def build_delete_params(data_id)
|
143
203
|
params = {
|
144
204
|
'params' => "[null,\"#{data_id}\"]"
|
145
205
|
}
|
146
|
-
|
147
206
|
params = URI.encode_www_form(params)
|
148
207
|
end
|
149
208
|
|
data/lib/galerts/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: galerts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emre Can Yılmaz
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.7'
|
27
|
-
description:
|
27
|
+
description: Ruby library to manage google alerts
|
28
28
|
email:
|
29
29
|
- emrecan@ecylmz.com
|
30
30
|
executables: []
|