magnews-ruby 0.1.0 → 0.2.0

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: 468f2da87827c283d63555722640ab4c5d64c240
4
- data.tar.gz: 85deedf30c5df8a5afcae9338c06025d92d7a05c
3
+ metadata.gz: d7d6992a0ff2a12f1342a3e8f61df456cbc04ab4
4
+ data.tar.gz: ce7790f142a4ad3dd5d9948cf2b459c058b08f52
5
5
  SHA512:
6
- metadata.gz: ef082b576bd83dde5253e58b846323de1115253416c4e8b258017cd04fc122f6081702be7ef885f3f406fb04e6be8a25dfded0aa1f5f0b66a042b874a8c38cf5
7
- data.tar.gz: 01c3f4f5855ec185680f9dc93208f997084991d3f51f91a398356b265c48aa8f1f33e3e805234590a0e7f2c46673a5ce3d0e13dd6481bdfbfab5ac11b634a79d
6
+ metadata.gz: 47ced1b71902c6911bd8cd41362cf6ce9d76404287c8ae5552c5c0e4ca68b4daf9ee2b29e5e277b792d63828e858b2acc83d999945fb21166d2271440fe7e11a
7
+ data.tar.gz: 6b27c36f716ac8bae1f42006d28c1352b5a80a5ec327aa3ae97006a124fac55ebb9303a6ca80024b26f9b730fc82ce1d354da36ebdabd5c6ea07464cde4866d6
data/.gitignore CHANGED
@@ -6,4 +6,7 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
+ /spec/examples.txt
9
10
  /tmp/
11
+ .ruby-version
12
+ .ruby-gemset
data/README.md CHANGED
@@ -22,7 +22,39 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Create a configuration file like this:
26
+
27
+ ```ruby
28
+ Magnews.configure do |config|
29
+ config.auth_token = Rails.application.secrets.magnews_token
30
+ config.iddatabase = Rails.configuration.x.magnews.database_id
31
+ config.logger = Rails.configuration.x.newsletter.logger
32
+ end
33
+ ```
34
+
35
+ ### Contact create
36
+
37
+ To create a contact use `.create!` method with subscription parameters (more infos [Magnews Rest API subscribe contact](http://support.magnews.it/en/ws/restcontacts.html#Subscribe_contact))
38
+
39
+ ```
40
+ Magnews::Contact.create!(subscription_params)
41
+ ```
42
+
43
+ ### Contacts list
44
+
45
+ List all subscribed contacts to a list use `.list_all`. It returns an hash with email and contact id.
46
+
47
+ ```
48
+ Magnews::Contact.list_all
49
+ ```
50
+
51
+ ### Contact delete
52
+
53
+ To delete a contact use `.delete!` method with email and options (optionally).
54
+
55
+ ```
56
+ Magnews::Contact.delete!('admin@example.com')
57
+ ```
26
58
 
27
59
  ## Development
28
60
 
@@ -21,6 +21,30 @@ module Magnews
21
21
  end
22
22
  end
23
23
 
24
+ def delete!(email, options={})
25
+ payload = { options: options.reverse_merge({ iddatabase: Magnews.iddatabase }), values: { email: email } }.to_json
26
+ RestClient.post(url_for("contacts/unsubscribe"), payload, common_headers) do |response, request, result, &block|
27
+ logger.info { response.body }
28
+ if (200..207).include? response.code
29
+ respond_to_200(response)
30
+ elsif Magnews::EXCEPTIONS_MAP[response.code].present?
31
+ raise Magnews::EXCEPTIONS_MAP[response.code].new(response, response.code)
32
+ else
33
+ response.return!(request, result, &block)
34
+ end
35
+ end
36
+ end
37
+
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!)
43
+ return {} if response.empty?
44
+ response.reject! { |r| r[:status] != "subscribed" }
45
+ response.each_with_object({}) { |r, obj| obj[r[:fields][:email]] = r[:idcontact] }
46
+ end
47
+
24
48
  def respond_to_200(response)
25
49
  body = JSON.parse(response.body).deep_symbolize_keys!
26
50
  if body[:ok]
@@ -1,3 +1,3 @@
1
1
  module Magnews
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filippo Gangi Dino
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-07-01 00:00:00.000000000 Z
12
+ date: 2015-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  requirements: []
203
203
  rubyforge_project:
204
- rubygems_version: 2.4.6
204
+ rubygems_version: 2.4.5
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: Unofficial Magnews REST API ruby interface