magnews-ruby 0.2.0 → 0.2.1
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 +9 -1
- data/lib/magnews/contact.rb +17 -4
- data/lib/magnews/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fa8edf30430535b385db8990d9d626339c7aebd
|
4
|
+
data.tar.gz: 9843c663db570fbb6444693ec9d30c4467df2a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae033966aa73286920618811ac8dc3acfbe9db44949b28fde2ac81c353b128cfada6cf0cbc0361faffafb2ab13978e44ddb82ae39fcdce5ce223f0b1778ccc27
|
7
|
+
data.tar.gz: 59e08aa36ff80bf419af29a982cbb1215592c3d045ee4a14ba16a061ba5712cb0e05335c369f7851c0f3cf6ad3611979e72c811834daabd27fdd357e02935bb5
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ To create a contact use `.create!` method with subscription parameters (more inf
|
|
40
40
|
Magnews::Contact.create!(subscription_params)
|
41
41
|
```
|
42
42
|
|
43
|
-
### Contacts list
|
43
|
+
### Contacts list all (subscribed)
|
44
44
|
|
45
45
|
List all subscribed contacts to a list use `.list_all`. It returns an hash with email and contact id.
|
46
46
|
|
@@ -48,6 +48,14 @@ List all subscribed contacts to a list use `.list_all`. It returns an hash with
|
|
48
48
|
Magnews::Contact.list_all
|
49
49
|
```
|
50
50
|
|
51
|
+
### Contacts list all (unsubscribed)
|
52
|
+
|
53
|
+
List all subscribed contacts to a list use `.list_unsubscribed`. It returns an hash with email and contact id.
|
54
|
+
|
55
|
+
```
|
56
|
+
Magnews::Contact.list_unsubscribed
|
57
|
+
```
|
58
|
+
|
51
59
|
### Contact delete
|
52
60
|
|
53
61
|
To delete a contact use `.delete!` method with email and options (optionally).
|
data/lib/magnews/contact.rb
CHANGED
@@ -36,15 +36,19 @@ module Magnews
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def list_all
|
39
|
-
|
40
|
-
response = RestClient.get(URI.escape(url_for("contacts/query?query=#{query}")), auth_header)
|
41
|
-
response = JSON.parse response
|
42
|
-
response.each(&:deep_symbolize_keys!)
|
39
|
+
response = query_users
|
43
40
|
return {} if response.empty?
|
44
41
|
response.reject! { |r| r[:status] != "subscribed" }
|
45
42
|
response.each_with_object({}) { |r, obj| obj[r[:fields][:email]] = r[:idcontact] }
|
46
43
|
end
|
47
44
|
|
45
|
+
def list_unsubscribed
|
46
|
+
response = query_users
|
47
|
+
return {} if response.empty?
|
48
|
+
response.reject! { |r| r[:status] != "unsubscribed" }
|
49
|
+
response.each_with_object({}) { |r, obj| obj[r[:fields][:email]] = r[:idcontact] }
|
50
|
+
end
|
51
|
+
|
48
52
|
def respond_to_200(response)
|
49
53
|
body = JSON.parse(response.body).deep_symbolize_keys!
|
50
54
|
if body[:ok]
|
@@ -60,6 +64,15 @@ module Magnews
|
|
60
64
|
values[key] = value.join(",") if value.is_a? Array
|
61
65
|
end
|
62
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def query_users
|
71
|
+
query = "SELECT * FROM CONTACTS WHERE iddatabase=#{Magnews.iddatabase}"
|
72
|
+
response = RestClient.get(URI.escape(url_for("contacts/query?query=#{query}")), auth_header)
|
73
|
+
response = JSON.parse response
|
74
|
+
response.each(&:deep_symbolize_keys!)
|
75
|
+
end
|
63
76
|
end
|
64
77
|
end
|
65
78
|
end
|
data/lib/magnews/version.rb
CHANGED