primotexto 0.1.0 → 0.1.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 +32 -3
- data/lib/primotexto/client/constants.rb +4 -0
- data/lib/primotexto/client/http.rb +2 -2
- data/lib/primotexto/client.rb +53 -2
- data/lib/primotexto/version.rb +1 -1
- data/primotexto.gemspec +2 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76f0e403cc818bc34074d2c133f6c6364d6b7a30
|
4
|
+
data.tar.gz: bc35eaf8b1cb39460a041a34d98aaffb7b0ec858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48ffcd5fe10be32969ee1cb8b63f6572603b84ee8cbc877ece3b49d41de462f15053c8c87414f2f50e2720d701d055b4dd81ffb48a02d016867ebbfd9a2b2346
|
7
|
+
data.tar.gz: 8297adaeea726ef22edf747c28d896fb011e74bae4b48ec5d03471526ddcb8f4246add46eee8efee8723f469be4e1afd6887f7f1b99e0ea09ee537e0bdcdf29b
|
data/README.md
CHANGED
@@ -10,6 +10,12 @@ Add this line to your application's Gemfile:
|
|
10
10
|
gem 'primotexto'
|
11
11
|
```
|
12
12
|
|
13
|
+
Or from Github to install the 'edge' version:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'primotexto', github: 'syntaxTerr0r/primotexto'
|
17
|
+
```
|
18
|
+
|
13
19
|
And then execute:
|
14
20
|
|
15
21
|
$ bundle
|
@@ -21,6 +27,7 @@ Or install it yourself as:
|
|
21
27
|
## Usage
|
22
28
|
|
23
29
|
All API methods are not implemented yet. Here is an exhaustive list of what is currently supported.
|
30
|
+
Methods naming try to follow the API naming, however some changes has been made to make some name more friendly.
|
24
31
|
|
25
32
|
### Initializing a new client
|
26
33
|
|
@@ -28,7 +35,7 @@ All API methods are not implemented yet. Here is an exhaustive list of what is c
|
|
28
35
|
pt = Primotexto.client(key: 'MY_SHINY_API_KEY')
|
29
36
|
```
|
30
37
|
|
31
|
-
Alternatively, you can define the key in
|
38
|
+
Alternatively, you can define the key in an `ENV` variable: `PRIMOTEXTO_API_KEY`
|
32
39
|
|
33
40
|
```ruby
|
34
41
|
pt = Primotexto.client
|
@@ -108,7 +115,7 @@ pt.get_unsubscribers_contacts
|
|
108
115
|
pt.post_unsubscribers_contacts(identifier: '+33612345678')
|
109
116
|
```
|
110
117
|
|
111
|
-
|
118
|
+
#### Removing a phone number from unsubscribers list
|
112
119
|
|
113
120
|
[API reference](https://www.primotexto.com/api/account/stats.asp)
|
114
121
|
|
@@ -132,7 +139,7 @@ pt.get_bounces_contacts
|
|
132
139
|
pt.post_bounces_contacts(identifier: '+33612345678')
|
133
140
|
```
|
134
141
|
|
135
|
-
|
142
|
+
#### Removing a phone number from bounces list
|
136
143
|
|
137
144
|
[API reference](https://www.primotexto.com/api/account/stats.asp)
|
138
145
|
|
@@ -140,6 +147,28 @@ pt.post_bounces_contacts(identifier: '+33612345678')
|
|
140
147
|
pt.delete_bounces_contacts(identifier: '+33612345678')
|
141
148
|
```
|
142
149
|
|
150
|
+
### Contacts lists
|
151
|
+
|
152
|
+
[API reference](https://www.primotexto.com/api/lists/contacts/index.asp)
|
153
|
+
|
154
|
+
#### Creating a list
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
vip_list = pt.post_lists(name: 'VIP People')
|
158
|
+
```
|
159
|
+
|
160
|
+
#### Adding a contact to a list
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
vip_contact = pt.post_list_contact(list_id: vip_list[:id], identifier: '+33612345678')
|
164
|
+
```
|
165
|
+
|
166
|
+
#### Removing a contact from a list
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
pt.delete_list_contact(list_id: vip_list[:id], contact_id: vip_contact[:id], identifier: '+33612345678')
|
170
|
+
```
|
171
|
+
|
143
172
|
### Getting you account stats
|
144
173
|
|
145
174
|
[API reference](https://www.primotexto.com/api/account/stats.asp)
|
@@ -47,6 +47,10 @@ module Primotexto
|
|
47
47
|
['get_unsubscribers_contacts', 'get_unsubscribers_default_contacts'],
|
48
48
|
['post_unsubscribers_contacts', 'post_unsubscribers_default_contacts_params'],
|
49
49
|
['delete_unsubscribers_contacts', 'delete_unsubscribers_default_contacts_params'],
|
50
|
+
'post_lists_params',
|
51
|
+
['post_list_contact', 'post_lists-id_params'],
|
52
|
+
['delete_list_contact', 'delete_lists-id_contacts-id_params'],
|
53
|
+
|
50
54
|
].freeze
|
51
55
|
end
|
52
56
|
end
|
@@ -52,10 +52,10 @@ module Primotexto
|
|
52
52
|
http_response.body
|
53
53
|
end
|
54
54
|
when Net::HTTPUnauthorized
|
55
|
-
|
55
|
+
fail AuthenticationError
|
56
56
|
else
|
57
57
|
error_code = JSON.parse(http_response.body)['code']
|
58
|
-
|
58
|
+
fail Error, "#{ERROR_CODES[error_code]} (code: #{error_code})"
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
data/lib/primotexto/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/inflector'
|
1
2
|
require "primotexto/client/constants"
|
2
3
|
require "primotexto/client/http"
|
3
4
|
|
@@ -9,6 +10,53 @@ module Primotexto
|
|
9
10
|
@key = options.fetch(:key) { ENV.fetch('PRIMOTEXTO_API_KEY') }
|
10
11
|
end
|
11
12
|
|
13
|
+
class << self
|
14
|
+
def ids_to_params(ids)
|
15
|
+
ids.map { |id| id_to_param(id) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def id_to_param(id)
|
19
|
+
parts = id.split('-')
|
20
|
+
name = ActiveSupport::Inflector.singularize(parts.first)
|
21
|
+
parts[0] = name
|
22
|
+
parts.join('_').to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def no_params_behaviour(verb, uri)
|
28
|
+
-> { send(verb, uri) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def params_behaviour(verb, uri)
|
32
|
+
-> (params) { send(verb, uri, params) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def params_with_ids_behaviour(verb, method, ids)
|
36
|
+
lambda do |params|
|
37
|
+
# Validating uri params presence
|
38
|
+
Client.ids_to_params(ids).each do |pid|
|
39
|
+
fail Error, "The '#{pid}' params is mandatory for this method" unless params.include?(pid)
|
40
|
+
end
|
41
|
+
|
42
|
+
method_with_ids = method.dup
|
43
|
+
|
44
|
+
# Replacing values
|
45
|
+
ids.each do |pid|
|
46
|
+
param_name = pid.split('-').first
|
47
|
+
param_value = params[Client.id_to_param(pid)]
|
48
|
+
method_with_ids.map! do |v|
|
49
|
+
(v == pid) ? "#{param_name}/#{param_value}" : v
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
uri = '/'
|
54
|
+
uri += method_with_ids.join('/')
|
55
|
+
send(verb, uri, params)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
12
60
|
API_METHODS_MAP.each do |api_method|
|
13
61
|
if api_method.is_a?(Array)
|
14
62
|
friendly_method = api_method.first
|
@@ -18,15 +66,18 @@ module Primotexto
|
|
18
66
|
method = api_method.split('_')
|
19
67
|
with_params = api_method.include?('params')
|
20
68
|
method.pop if with_params
|
69
|
+
|
70
|
+
ids = method.select { |i| i.include?('-id') }
|
71
|
+
|
21
72
|
friendly_method = method.join('_') if friendly_method.nil?
|
22
73
|
verb = method.shift
|
23
74
|
uri = '/'
|
24
75
|
uri += method.join('/')
|
25
76
|
|
26
77
|
if with_params
|
27
|
-
behaviour =
|
78
|
+
behaviour = (ids.any?) ? params_with_ids_behaviour(verb, method, ids) : params_behaviour(verb, uri)
|
28
79
|
else
|
29
|
-
behaviour =
|
80
|
+
behaviour = no_params_behaviour(verb, uri)
|
30
81
|
end
|
31
82
|
define_method(friendly_method.to_sym, &behaviour)
|
32
83
|
end
|
data/lib/primotexto/version.rb
CHANGED
data/primotexto.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["synthax.terror@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Ruby client for the Primotexto API}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{An unofficial Ruby client for the Primotexto API}
|
14
14
|
spec.homepage = "https://github.com/syntaxTerr0r/primotexto"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency "activesupport", ">= 2.2.1"
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.11"
|
23
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: primotexto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sébastien Poudat
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +66,7 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
55
|
-
description:
|
69
|
+
description: An unofficial Ruby client for the Primotexto API
|
56
70
|
email:
|
57
71
|
- synthax.terror@gmail.com
|
58
72
|
executables: []
|