magnews-ruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7d6992a0ff2a12f1342a3e8f61df456cbc04ab4
4
- data.tar.gz: ce7790f142a4ad3dd5d9948cf2b459c058b08f52
3
+ metadata.gz: 0fa8edf30430535b385db8990d9d626339c7aebd
4
+ data.tar.gz: 9843c663db570fbb6444693ec9d30c4467df2a83
5
5
  SHA512:
6
- metadata.gz: 47ced1b71902c6911bd8cd41362cf6ce9d76404287c8ae5552c5c0e4ca68b4daf9ee2b29e5e277b792d63828e858b2acc83d999945fb21166d2271440fe7e11a
7
- data.tar.gz: 6b27c36f716ac8bae1f42006d28c1352b5a80a5ec327aa3ae97006a124fac55ebb9303a6ca80024b26f9b730fc82ce1d354da36ebdabd5c6ea07464cde4866d6
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).
@@ -36,15 +36,19 @@ module Magnews
36
36
  end
37
37
 
38
38
  def list_all
39
- query = "SELECT * FROM CONTACTS WHERE iddatabase=#{Magnews.iddatabase}"
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
@@ -1,3 +1,3 @@
1
1
  module Magnews
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magnews-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filippo Gangi Dino