galerts 0.0.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -7
- data/lib/galerts.rb +3 -60
- data/lib/galerts/alert.rb +4 -4
- data/lib/galerts/defaults.rb +67 -0
- data/lib/galerts/manager.rb +30 -24
- data/lib/galerts/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5cb0c39e02378baf953220a1a115b974de39d7b
|
4
|
+
data.tar.gz: a50d19fb9b533aa49cc893ad47177bc3a3748763
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fb5d10dde9537a902a3f673bdd53a8cbd29fb5c7928f8a56365d09c5ded9428e9c1e381e6d4c698b24b704dc9b499af4129ed59fb9703be0b3e01cf3f91b4ea
|
7
|
+
data.tar.gz: 6ae338a36a44410083d0259de4e14dccf718fa876f04d71eb5750fc17688d829cba79115194753403eb8ee618e5362b01dc5f0b45ca46655bf5e436c681e525c
|
data/README.md
CHANGED
@@ -27,10 +27,11 @@ manager = Galerts::Manager.new('example@gmail.com', 'password')
|
|
27
27
|
|
28
28
|
# List alerts
|
29
29
|
alerts = manager.alerts
|
30
|
+
sample_alert = alerts.last
|
30
31
|
|
31
32
|
# Create a new alert for on Google News Turkey in real time delivering alerts
|
32
33
|
# via RSS
|
33
|
-
manager.create("my keywords", {
|
34
|
+
new_alert = manager.create("my keywords", {
|
34
35
|
:frequency => Galerts::RT,
|
35
36
|
:domain => 'com.tr',
|
36
37
|
:language => "tr",
|
@@ -41,19 +42,17 @@ manager.create("my keywords", {
|
|
41
42
|
}
|
42
43
|
)
|
43
44
|
|
44
|
-
alert = manager.alerts.last
|
45
|
-
|
46
45
|
# Update the query of this alert
|
47
|
-
|
48
|
-
manager.update(
|
46
|
+
sample_alert.query = "updated keyword"
|
47
|
+
manager.update(sample_alert)
|
49
48
|
|
50
49
|
# Find examples
|
51
50
|
manager.find_by_query("keyword")
|
52
51
|
manager.find_by_delivery(Galerts::RSS)
|
53
52
|
manager.find({query: "keyword", delivery: Galerts::RSS})
|
54
53
|
|
55
|
-
# Delete an alert
|
56
|
-
manager.delete(
|
54
|
+
# Delete an alert
|
55
|
+
manager.delete(sample_alert)
|
57
56
|
|
58
57
|
```
|
59
58
|
|
data/lib/galerts.rb
CHANGED
@@ -1,64 +1,7 @@
|
|
1
|
-
|
2
|
-
# URLs
|
3
|
-
CREATE_ALERT_URL = 'https://www.google.com/alerts/create?'
|
4
|
-
DELETE_ALERT_URL = 'https://www.google.com/alerts/delete?'
|
5
|
-
MODIFY_ALERT_URL = 'https://www.google.com/alerts/modify?'
|
6
|
-
GOOGLE_LOGIN_URL = 'https://accounts.google.com/ServiceLogin?'
|
7
|
-
ALERTS_URL = 'https://www.google.com/alerts'
|
8
|
-
LOGIN_URL = "#{GOOGLE_LOGIN_URL}service=alerts&continue=#{ALERTS_URL}"
|
9
|
-
|
10
|
-
# Google Return HTML Definitions
|
11
|
-
ALERT_EXIST = "[null,11,null,\"\"]"
|
12
|
-
ALERT_SOMETHING_WENT_WRONG = "[null,7,null,\"\"]"
|
13
|
-
ALERT_NOT_EXIST = "[null,5,null,\"\"]"
|
14
|
-
# Google Value
|
15
|
-
BEST_RESULTS = 'Only the best results'
|
16
|
-
ALL_RESULTS = 'All results'
|
17
|
-
|
18
|
-
HOW_MANY_TYPES = {
|
19
|
-
ALL_RESULTS => 2,
|
20
|
-
BEST_RESULTS => 3
|
21
|
-
}
|
22
|
-
|
23
|
-
RSS = 'rss'
|
24
|
-
EMAIL = 'email'
|
25
|
-
|
26
|
-
DELIVERY_TYPES = {
|
27
|
-
EMAIL => 1,
|
28
|
-
RSS => 2
|
29
|
-
}
|
30
|
-
|
31
|
-
|
32
|
-
RT = 'As it happens'
|
33
|
-
DAILY = 'Once a day'
|
34
|
-
WEEKLY = 'Once a week'
|
35
|
-
|
36
|
-
FREQ_TYPES = {
|
37
|
-
RT => 1,
|
38
|
-
DAILY => 2,
|
39
|
-
WEEKLY => 3
|
40
|
-
}
|
41
|
-
|
42
|
-
|
43
|
-
BLOGS = 'Blogs'
|
44
|
-
NEWS = 'News'
|
45
|
-
WEB = 'Web'
|
46
|
-
VIDEOS = 'Videos'
|
47
|
-
BOOKS = 'Books'
|
48
|
-
DISCUSSIONS = 'Discussions'
|
49
|
-
|
50
|
-
SOURCES_TYPES = {
|
51
|
-
BLOGS => 1,
|
52
|
-
NEWS => 2,
|
53
|
-
WEB => 3,
|
54
|
-
VIDEOS => 5,
|
55
|
-
BOOKS => 6,
|
56
|
-
DISCUSSIONS => 7
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
1
|
+
require File.expand_path('../galerts/defaults', __FILE__)
|
60
2
|
require File.expand_path('../galerts/alert', __FILE__)
|
61
3
|
require File.expand_path('../galerts/manager', __FILE__)
|
62
4
|
require File.expand_path('../galerts/version', __FILE__)
|
63
5
|
|
64
|
-
|
6
|
+
module Galerts
|
7
|
+
end
|
data/lib/galerts/alert.rb
CHANGED
@@ -6,12 +6,12 @@ module Galerts
|
|
6
6
|
default_options = {
|
7
7
|
id: 0,
|
8
8
|
data_id: 0,
|
9
|
-
domain:
|
9
|
+
domain: DOMAIN,
|
10
10
|
frequency: RT,
|
11
|
-
sources:
|
12
|
-
language:
|
11
|
+
sources: AUTOMATIC,
|
12
|
+
language: LANGUAGE,
|
13
13
|
how_many: ALL_RESULTS,
|
14
|
-
region:
|
14
|
+
region: ANYWHERE,
|
15
15
|
delivery: RSS,
|
16
16
|
feed_url: nil
|
17
17
|
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Galerts
|
2
|
+
# URLs
|
3
|
+
CREATE_ALERT_URL = 'https://www.google.com/alerts/create?'
|
4
|
+
DELETE_ALERT_URL = 'https://www.google.com/alerts/delete?'
|
5
|
+
MODIFY_ALERT_URL = 'https://www.google.com/alerts/modify?'
|
6
|
+
GOOGLE_LOGIN_URL = 'https://accounts.google.com/ServiceLogin?'
|
7
|
+
ALERTS_URL = 'https://www.google.com/alerts'
|
8
|
+
LOGIN_URL = "#{GOOGLE_LOGIN_URL}service=alerts&continue=#{ALERTS_URL}"
|
9
|
+
|
10
|
+
# Google Return HTML Definitions
|
11
|
+
ALERT_EXIST = "[null,11,null,\"\"]"
|
12
|
+
ALERT_SOMETHING_WENT_WRONG = "[null,7,null,\"\"]"
|
13
|
+
ALERT_NOT_EXIST = "[null,5,null,\"\"]"
|
14
|
+
# Google Value
|
15
|
+
BEST_RESULTS = 'Only the best results'
|
16
|
+
ALL_RESULTS = 'All results'
|
17
|
+
|
18
|
+
HOW_MANY_TYPES = {
|
19
|
+
ALL_RESULTS => 2,
|
20
|
+
BEST_RESULTS => 3
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
RSS = 'rss'
|
25
|
+
EMAIL = 'email'
|
26
|
+
|
27
|
+
DELIVERY_TYPES = {
|
28
|
+
EMAIL => 1,
|
29
|
+
RSS => 2
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
RT = 'As it happens'
|
34
|
+
DAILY = 'Once a day'
|
35
|
+
WEEKLY = 'Once a week'
|
36
|
+
|
37
|
+
FREQ_TYPES = {
|
38
|
+
RT => 1,
|
39
|
+
DAILY => 2,
|
40
|
+
WEEKLY => 3
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
BLOGS = 'Blogs'
|
45
|
+
NEWS = 'News'
|
46
|
+
WEB = 'Web'
|
47
|
+
VIDEOS = 'Videos'
|
48
|
+
BOOKS = 'Books'
|
49
|
+
DISCUSSIONS = 'Discussions'
|
50
|
+
|
51
|
+
SOURCES_TYPES = {
|
52
|
+
BLOGS => 1,
|
53
|
+
NEWS => 2,
|
54
|
+
WEB => 3,
|
55
|
+
VIDEOS => 5,
|
56
|
+
BOOKS => 6,
|
57
|
+
DISCUSSIONS => 7
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
# Default alert value
|
62
|
+
DOMAIN = 'com'
|
63
|
+
AUTOMATIC = ''
|
64
|
+
LANGUAGE = 'en'
|
65
|
+
REGION = 'US'
|
66
|
+
ANYWHERE = 'anywhere'
|
67
|
+
end
|
data/lib/galerts/manager.rb
CHANGED
@@ -60,7 +60,7 @@ module Galerts
|
|
60
60
|
data_id: alert[1],
|
61
61
|
domain: alert[2][3][2],
|
62
62
|
language: alert[2][3][3][1],
|
63
|
-
region: alert[2][3][3][2],
|
63
|
+
region: alert[2][3].last == 1 ? alert[2][3][3][2] : ANYWHERE,
|
64
64
|
frequency: FREQ_TYPES.invert[alert[2][6][0][4]],
|
65
65
|
sources: SOURCES_TYPES.invert[alert[2][4]],
|
66
66
|
how_many: HOW_MANY_TYPES.invert[alert[2][5]],
|
@@ -71,18 +71,6 @@ module Galerts
|
|
71
71
|
result
|
72
72
|
end
|
73
73
|
|
74
|
-
def find(attrs = {})
|
75
|
-
alerts.select{|a| attrs.keys.inject(true) {|memo,k| memo = memo && attrs[k] == a.send(k) }}
|
76
|
-
end
|
77
|
-
|
78
|
-
# Metaprogramming for find_by commands
|
79
|
-
variables = Galerts::Alert.new("").instance_variables.map {|m| m.to_s.delete('@')}
|
80
|
-
variables.each do |variable|
|
81
|
-
define_method("find_by_#{variable}") do |argument|
|
82
|
-
find({variable.to_sym => argument})
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
74
|
def build_params(alert, action)
|
87
75
|
# set delivery and frequency parameters
|
88
76
|
if alert.delivery == EMAIL
|
@@ -108,15 +96,28 @@ module Galerts
|
|
108
96
|
sources_text = sources_text.chop + ']'
|
109
97
|
end
|
110
98
|
|
99
|
+
if alert.region == ANYWHERE
|
100
|
+
region = REGION
|
101
|
+
anywhere = true
|
102
|
+
else
|
103
|
+
region = alert.region
|
104
|
+
anywhere = false
|
105
|
+
end
|
106
|
+
|
111
107
|
# TODO: need more readable
|
112
108
|
if action == 0 # create
|
113
109
|
params = {
|
114
|
-
'params' => "[null,[null,null,null,[null,\"#{alert.query}\",\"#{alert.domain}\",[null,\"#{alert.language}\",\"#{
|
110
|
+
'params' => "[null,[null,null,null,[null,\"#{alert.query}\",\"#{alert.domain}\",[null,\"#{alert.language}\",\"#{region}\"],null,null,null,#{anywhere ? 0 : 1},1],#{sources_text},#{HOW_MANY_TYPES[alert.how_many]},[[null,#{delivery_and_frequency},\"#{alert.language + '-' + region.upcase}\",null,null,null,null,null,'0']]]]"
|
115
111
|
}
|
116
112
|
return URI.encode_www_form(params)
|
117
113
|
elsif action == 1 # edit
|
118
114
|
params = {
|
119
|
-
'params' => "[null,\"#{alert.data_id}\",[null,null,null,[null,\"#{alert.query}\",\"#{alert.domain}\",[null,\"#{alert.language}\",\"#{
|
115
|
+
'params' => "[null,\"#{alert.data_id}\",[null,null,null,[null,\"#{alert.query}\",\"#{alert.domain}\",[null,\"#{alert.language}\",\"#{region}\"],null,null,null,#{anywhere ? 1 : 0},1],#{sources_text},#{HOW_MANY_TYPES[alert.how_many]},[[null,#{delivery_and_frequency},\"#{alert.language + '-' + region.upcase}\",null,null,null,null,null,\"#{alert.id}\"]]]]"
|
116
|
+
}
|
117
|
+
return URI.encode_www_form(params)
|
118
|
+
elsif action == 2 # delete
|
119
|
+
params = {
|
120
|
+
'params' => "[null,\"#{alert.data_id}\"]"
|
120
121
|
}
|
121
122
|
return URI.encode_www_form(params)
|
122
123
|
end
|
@@ -166,23 +167,28 @@ module Galerts
|
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
169
|
-
def
|
170
|
-
params = {
|
171
|
-
'params' => "[null,\"#{data_id}\"]"
|
172
|
-
}
|
173
|
-
params = URI.encode_www_form(params)
|
174
|
-
end
|
175
|
-
|
176
|
-
def delete(data_id)
|
170
|
+
def delete(alert)
|
177
171
|
x = alerts_page.css('div#gb-main div.main-page script').text.split(',').last[1..-4]
|
178
|
-
response = @agent.post("#{DELETE_ALERT_URL}x=#{x}",
|
172
|
+
response = @agent.post("#{DELETE_ALERT_URL}x=#{x}", build_params(alert, 2), {'Content-Type' => 'application/x-www-form-urlencoded'})
|
179
173
|
|
180
174
|
if response.body == ALERT_NOT_EXIST
|
181
175
|
raise "Alert not exist!"
|
182
176
|
elsif response.body == ALERT_SOMETHING_WENT_WRONG
|
183
177
|
raise "Something went wrong!" # internal error, html changed maybe
|
184
178
|
end
|
179
|
+
true
|
180
|
+
end
|
181
|
+
|
182
|
+
def find(attrs = {})
|
183
|
+
alerts.select{|a| attrs.keys.inject(true) {|memo,k| memo = memo && attrs[k] == a.send(k) }}
|
185
184
|
end
|
186
185
|
|
186
|
+
# Metaprogramming for find_by commands
|
187
|
+
variables = Galerts::Alert.new("").instance_variables.map {|m| m.to_s.delete('@')}
|
188
|
+
variables.each do |variable|
|
189
|
+
define_method("find_by_#{variable}") do |argument|
|
190
|
+
find({variable.to_sym => argument})
|
191
|
+
end
|
192
|
+
end
|
187
193
|
end
|
188
194
|
end
|
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: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emre Can Yılmaz
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- galerts.gemspec
|
38
38
|
- lib/galerts.rb
|
39
39
|
- lib/galerts/alert.rb
|
40
|
+
- lib/galerts/defaults.rb
|
40
41
|
- lib/galerts/manager.rb
|
41
42
|
- lib/galerts/version.rb
|
42
43
|
homepage: https://github.com/pivotus/galerts
|