cleverelements 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f032559d13407aa76df111ffb09fd325c57a8b7
4
+ data.tar.gz: 4ff2416e9cba57139dd24df260f3d0bdcf62ceb1
5
+ SHA512:
6
+ metadata.gz: 0a03f2dce5745b0c3e7316e9884849b2747b746513701bafe0ddcebed3e4a4cbc9580db6f3ceb8c4fa590dab858940daee12e6b4d10f8f9c96e049706532c0c6
7
+ data.tar.gz: 13a1f2ed432f7a4a4e86d60e10693b859af9b3772c7d9126f6e7d530efe38c75b7a1e9c4abee27644423e2af2e453e1454c17d8bc399d5b42246a0ae061d586b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cleverelements.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Zdravko Evstatiev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ # cleverelements
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = "test/*_test.rb"
7
+ end
8
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cleverelements"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cleverelements/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.required_ruby_version = '~> 2.0'
8
+ spec.name = "cleverelements"
9
+ spec.version = CleverElements::VERSION
10
+ spec.authors = ["Despark"]
11
+ spec.email = ["contact@despark.com"]
12
+
13
+ spec.summary = "A ruby gem to help you implement [Clever Elements'](http://www.cleverelements.com/, 'Clever Elements') API in your projects. Detailed API documentations can be found here: [http://support.cleverelements.com/kb/api/](http://support.cleverelements.com/kb/api/, 'View API docs')."
14
+ spec.description = "The API works with the network protocol SOAP (Simple Object Access Protocol). SOAP libraries can be found in many modern programming languages such as PHP, Python, Java and C++. SOAP therefore provides a good basis for simple cross-language communication. The basis for SOAP is the WSDL file, in which all functions and parameters of the API are described. The WSDL file is provided in XML format and can be read by many editors (e.g. Aptana). [More Info about our API](http://support.cleverelements.com/kb/api/)"
15
+ spec.homepage = "http://www.cleverelements.com/"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ spec.add_dependency "savon", "~> 2.10", ">= 2.10.0"
26
+ end
@@ -0,0 +1,7 @@
1
+ require 'cleverelements/version'
2
+ require 'cleverelements/client'
3
+ require 'cleverelements/subscribers'
4
+ require 'cleverelements/lists'
5
+
6
+ module CleverElements
7
+ end
@@ -0,0 +1,89 @@
1
+ require 'savon'
2
+ require 'cleverelements/lists'
3
+ require 'cleverelements/subscribers'
4
+
5
+ module CleverElements
6
+ class Client
7
+ API_VERSION = "1.0"
8
+ attr_reader :savon
9
+
10
+ def initialize(api_id, api_key, mode = 'test')
11
+ # cli = CleverElements::Client.new('195753', 'ua4zhTpLPaZ9wfpD', 'live')
12
+ # cli.lists.all
13
+ # cli.subscribers.find_by_email('email@example.org')
14
+ # cli.request(:api_get_list)
15
+ # cli.request(:api_get_list_details, {listID: 335333})
16
+ # sub_proxy = CleverElements::Subscribers.new(cli)
17
+ # sub_proxy.find_by_email('email@example.org')
18
+
19
+ @savon = Savon.client do
20
+ wsdl 'http://api.sendcockpit.com/server.php?wsdl'
21
+ convert_request_keys_to :none
22
+ soap_header({
23
+ validate: {
24
+ userid: api_id,
25
+ apikey: api_key,
26
+ version: API_VERSION,
27
+ mode: mode,
28
+ }
29
+ })
30
+ end
31
+ define_methods
32
+ end
33
+
34
+ def request(operation, data = {})
35
+ @savon.call(operation, build_data(operation, data))
36
+ end
37
+
38
+ def build(operation, data = {})
39
+ @savon.operation(operation).build(build_data(operation, data)).to_s
40
+ end
41
+
42
+ def define_methods
43
+ @savon.operations.each do |method|
44
+ self.class.send(:define_method, method) do |args = {}|
45
+ request(method, args)
46
+ end
47
+ end
48
+ end
49
+
50
+ def subscribers
51
+ CleverElements::Subscribers.new(self)
52
+ end
53
+
54
+ def lists
55
+ CleverElements::Lists.new(self)
56
+ end
57
+
58
+ private
59
+ def build_data(operation, data)
60
+ hash = {}
61
+ if operation_ct[operation]
62
+ hash[:message] = {operation_ct[operation] => data}
63
+ end
64
+ hash
65
+ end
66
+
67
+ def operation_ct
68
+ # wsdl.parser.document.css('message[name*=Request]').first.children.css('part').first.attributes["name"].value
69
+ {
70
+ api_add_subscriber: :ctSubscriberRequest,
71
+ api_add_subscriber_doi: :ctSubscriberRequest,
72
+ api_add_subscriber_field: :ctAddSubscriberFields,
73
+ api_delete_list: :ctListDetailsRequest,
74
+ api_delete_subscriber: :ctGetSubscriberIDListShort,
75
+ api_delete_subscriber_field: :ctDeleteSubscriberFields,
76
+ api_get_list_details: :ctListDetailsRequest,
77
+ api_add_list: :ctAddListRequest,
78
+ api_get_subscriber: :ctListRequest,
79
+ api_get_subscriber_details: :ctListRequest,
80
+ api_get_subscriber_by_email: :ctSubscriberEmailRequest,
81
+ api_get_subscriber_history: :ctGetSubscriberID,
82
+ api_get_subscriber_subscriptions: :ctSubscriberSubscriptionsRequest,
83
+ api_get_subscriber_unsubscribes: :ctListRequest,
84
+ api_unsubscribe_subscriber_from_all: :ctGetSubscriberIDList,
85
+ api_unsubscribe_subscriber_from_list: :ctGetSubscriberIDList,
86
+ }
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,37 @@
1
+ require 'cleverelements/resource'
2
+
3
+ module CleverElements
4
+ class Lists < Resource
5
+ def all
6
+ @client.api_get_list.body
7
+ end
8
+
9
+ def find(id)
10
+ @client.api_get_list_details({listID: id}).body
11
+ end
12
+
13
+ def create(name = "", description = "")
14
+ @client.api_add_list(listName: name, listDescription: description).body
15
+ end
16
+
17
+ def destroy(id)
18
+ @client.api_delete_list({listID: id}).body
19
+ end
20
+
21
+ def get_subscribers(list_id, offset = 0, limit = 100)
22
+ # cli.lists.get_subscribers(335333, 0, 100)
23
+ @client.api_get_subscriber({listID: list_id, start: offset, count: limit}).body
24
+ end
25
+
26
+ def get_subscribers_with_details(list_id, offset = 0, limit = 100)
27
+ # cli.lists.get_subscribers_with_details(335333, 0, 100)
28
+ @client.api_get_subscriber_details({listID: list_id, start: offset, count: limit}).body
29
+ end
30
+
31
+ def get_unsubscribed(list_id, offset = 0, limit = 100)
32
+ # cli.lists.get_unsubscribed(335333, 0, 100)
33
+ @client.api_get_subscriber_unsubscribes({listID: list_id, start: offset, count: limit}).body
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,7 @@
1
+ module CleverElements
2
+ class Resource
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,112 @@
1
+ require 'cleverelements/resource'
2
+
3
+ module CleverElements
4
+ class Subscribers < Resource
5
+ def history_for(id)
6
+ @client.api_get_subscriber_history({subscriberID: id}).body
7
+ end
8
+
9
+ def find_by_email(email)
10
+ @client.api_get_subscriber_by_email({email: email}).body
11
+ end
12
+
13
+ def get_subscriptions(id)
14
+ @client.api_get_subscriber_subscriptions({subscriberID: id}).body
15
+ end
16
+
17
+ def custom_fields
18
+ @client.api_get_subscriber_fields.body
19
+ end
20
+
21
+ def create_custom_field(name, type = 1)
22
+ @client.api_add_subscriber_field(customFieldName: name, customFieldType: type).body
23
+ end
24
+
25
+ def destroy_custom_field(id)
26
+ @client.api_delete_subscriber_field(customFieldID: id).body
27
+ end
28
+
29
+ def create(attributes)
30
+ # attributes = [
31
+ # {
32
+ # list_id: 335333,
33
+ # email: "2email@example.org",
34
+ # custom_fields: [
35
+ # {field_id: 818718, field_value: 'Master'},
36
+ # ]
37
+ # },
38
+ # {
39
+ # list_id: 335333,
40
+ # email: "3email@example.org",
41
+ # custom_fields: [
42
+ # {field_id: 818718, field_value: 'The Master'},
43
+ # ]
44
+ # }
45
+ # ]
46
+ @client.api_add_subscriber(build_subscriber_list(attributes)).body
47
+ end
48
+
49
+ def create_doi(attributes)
50
+ @client.api_add_subscriber_doi(build_subscriber_list(attributes)).body
51
+ end
52
+
53
+ def unsubscribe(subscriber_list)
54
+ # attributes = [
55
+ # {id: 290099412, list_id: 335333},
56
+ # {id: 290086837, list_id: 335333}
57
+ # ]
58
+
59
+ @client.api_unsubscribe_subscriber_from_list(build_subscriber_id_list(subscriber_list)).body
60
+ end
61
+
62
+ def unsubscribe_from_all(subscriber_list)
63
+ @client.api_unsubscribe_subscriber_from_all(build_subscriber_id_list(subscriber_list)).body
64
+ end
65
+
66
+ def destroy(ids)
67
+ # ids = [290099412, 290099401]
68
+ @client.api_delete_subscriber(build_subscriber_id_list_short(ids)).body
69
+ end
70
+
71
+ private
72
+ def build_subscriber_id_list_short(ids)
73
+ {
74
+ subscriberIDListShort: {
75
+ item: ids.map do |id|
76
+ {subscriberID: id}
77
+ end
78
+ }
79
+ }
80
+ end
81
+
82
+ def build_subscriber_id_list(attributes)
83
+ {
84
+ subscriberIDList: {
85
+ item: attributes.map do |attr|
86
+ {subscriberID: attr[:id], listID: attr[:list_id]}
87
+ end
88
+ }
89
+ }
90
+ end
91
+
92
+ def build_subscriber_list(attributes)
93
+ attributes_array = attributes.map do |attributes_hsh|
94
+ {
95
+ listID: attributes_hsh[:list_id],
96
+ email: attributes_hsh[:email],
97
+ customFields: {
98
+ item: build_custom_fields_array(attributes_hsh[:custom_fields])
99
+ }
100
+ }
101
+ end
102
+ {subscriberList: {item: attributes_array}}
103
+ end
104
+
105
+ def build_custom_fields_array(custom_fields)
106
+ custom_fields.map do |custom_fields_hsh|
107
+ { customFieldID: custom_fields_hsh[:field_id],
108
+ customFieldValue: custom_fields_hsh[:field_value] }
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ module CleverElements
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cleverelements
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Despark
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: savon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.10'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.10.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.10'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.10.0
61
+ description: The API works with the network protocol SOAP (Simple Object Access Protocol).
62
+ SOAP libraries can be found in many modern programming languages such as PHP, Python,
63
+ Java and C++. SOAP therefore provides a good basis for simple cross-language communication.
64
+ The basis for SOAP is the WSDL file, in which all functions and parameters of the
65
+ API are described. The WSDL file is provided in XML format and can be read by many
66
+ editors (e.g. Aptana). [More Info about our API](http://support.cleverelements.com/kb/api/)
67
+ email:
68
+ - contact@despark.com
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - ".gitignore"
74
+ - CODE_OF_CONDUCT.md
75
+ - Gemfile
76
+ - LICENSE.txt
77
+ - README.md
78
+ - Rakefile
79
+ - bin/console
80
+ - bin/setup
81
+ - cleverelements.gemspec
82
+ - lib/cleverelements.rb
83
+ - lib/cleverelements/client.rb
84
+ - lib/cleverelements/lists.rb
85
+ - lib/cleverelements/resource.rb
86
+ - lib/cleverelements/subscribers.rb
87
+ - lib/cleverelements/version.rb
88
+ homepage: http://www.cleverelements.com/
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '2.0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.5
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: 'A ruby gem to help you implement [Clever Elements''](http://www.cleverelements.com/,
112
+ ''Clever Elements'') API in your projects. Detailed API documentations can be found
113
+ here: [http://support.cleverelements.com/kb/api/](http://support.cleverelements.com/kb/api/,
114
+ ''View API docs'').'
115
+ test_files: []