DashaMailRb 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91a40407e341f39c2c69b46912f2e8433241308c
4
+ data.tar.gz: e0f82857a6903f74cf08e347f1db980fca84ac1a
5
+ SHA512:
6
+ metadata.gz: 26e0c50494de3efb91d2b4648bf410591c5ea44b74549e47a05f9bbd6b1ee17829d2c18c6c05354e53489e361b3debe454ba2dd8572ca230101f0d7a5954e1dd
7
+ data.tar.gz: 57dc99884eea31f7d81e61ad3aac2f3e0585e4e2b29f49e2e544ed0452d47f770e72e7cf9f74fc62bf79a0cf1a8f90d37193011068554ac2b9369db3e132ff26
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in DashaMailRb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 TODO: Write your name
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.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # DashaMailRb
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/DashaMailRb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'DashaMailRb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install DashaMailRb
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/DashaMailRb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the DashaMailRb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/DashaMailRb/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "DashaMailRb"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "DashaMailRb/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "DashaMailRb"
7
+ spec.version = DashaMailRb::VERSION
8
+ spec.authors = ["Alexandr Prokopenko"]
9
+ spec.email = ["prokopenko@igc.ru"]
10
+ spec.summary = %q{Interface for dashamail.ru service API}
11
+ spec.description = %q{Interface for dashamail.ru service API}
12
+ spec.homepage = "https://github.com/DashaMail/DashamailRb"
13
+ spec.license = "MIT"
14
+
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 2.0"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,6 @@
1
+ require "DashaMailRb/version"
2
+
3
+ module DashaMailRb
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,7 @@
1
+ module Dashamail
2
+ class ApiException < StandardError
3
+ end
4
+
5
+ class NoDataException < ApiException
6
+ end
7
+ end
@@ -0,0 +1,92 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Dashamail
5
+ class Connection
6
+
7
+ API_URL = 'https://api.dashamail.com'
8
+
9
+ # Initializes new connection instance
10
+ #
11
+ # @param username [String] Service username
12
+ # @param password [String] Password
13
+ def initialize(username, password, endpoint = API_URL)
14
+ @username, @password = username, password
15
+ @endpoint = endpoint
16
+ end
17
+
18
+ attr_reader :endpoint
19
+
20
+ # Memoized Faraday connection factory
21
+ #
22
+ # @return Faraday connection instance
23
+ def connection
24
+ @conn ||= Faraday.new(:url => endpoint) do |faraday|
25
+ faraday.request :url_encoded
26
+ faraday.response :json
27
+ faraday.adapter Faraday.default_adapter
28
+ end
29
+ end
30
+
31
+ # Invokes API method by name
32
+ #
33
+ # @param method [String] Method name, corresponding API reference https://dashamail.ru/api/
34
+ # @param params [Hash] Params to be passed
35
+ def call_method(method, params = {})
36
+ response = connection.post '/', {method: method}.merge(credentials).merge(params)
37
+ err_code = response.body["response"]["msg"]["err_code"]
38
+
39
+ case err_code
40
+ when 0
41
+ response.body["response"]["data"]
42
+ when 4
43
+ raise Dashamail::NoDataException.new(response.body["response"]["msg"]["text"])
44
+ else
45
+ raise Dashamail::ApiException.new(response.body["response"]["msg"]["text"])
46
+ end
47
+ end
48
+
49
+ # Invokes 'lists.get' API method
50
+ #
51
+ # @param params [Hash] Params to be passed
52
+ # @return [Array] Array of Dashamail::List instances
53
+ def lists(params = {})
54
+ call_method('lists.get', params).map {|list_raw| Dashamail::List.new(self, list_raw)}
55
+ end
56
+
57
+
58
+ # Invokes 'lists.get' API method to retrieve single List object
59
+ #
60
+ # @param id [Fixnum] List id
61
+ # @return [Dashamail::List] List instance
62
+ def get_list(id)
63
+ lists(list_id: id)[0]
64
+ end
65
+
66
+ # 'list.get' method alias
67
+ #
68
+ alias_method :get, :lists
69
+
70
+ # Invokes 'lists.get_member' API method
71
+ #
72
+ # @param email [String] Email for search
73
+ # @return [Array] Array of Dashamail::Member instances
74
+ def get_member(email)
75
+ call_method('lists.get_member', {email: email}).map {|member| Dashamail::Member.new(connection, member)}
76
+ end
77
+
78
+ # Invokes 'lists.unsubscribe_member' API method
79
+ #
80
+ # @param params [Hash] Params to be passed
81
+ # @return [Fixnum] Count of unsubscribed members
82
+ def unsubscribe_member(params)
83
+ call_method('lists.unsubscribe_member', params)['unsubscribed']
84
+ end
85
+
86
+ private
87
+
88
+ def credentials
89
+ {username: @username, password: @password}
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ module Dashamail
2
+ # Mailing list representation class
3
+ class List < Model
4
+ attr_reader :raw
5
+
6
+ FIELDS = [
7
+ :id,
8
+ :state,
9
+ :count_active,
10
+ :count_all,
11
+ :name,
12
+ :description,
13
+ :company,
14
+ :abuse_name,
15
+ :phone,
16
+ :address,
17
+ :city,
18
+ :url
19
+ ]
20
+
21
+ FIELDS.each do |f|
22
+ attr_reader f
23
+ end
24
+
25
+ # Initialize new list instance
26
+ #
27
+ # @param connection [Pachkin::Connection] Active connection
28
+ # @param doc [Hash] API object data
29
+ def initialize(connection, doc)
30
+ super(connection, doc)
31
+ FIELDS.each do |field|
32
+ instance_variable_set :"@#{field}", doc[field.to_s]
33
+ end
34
+ end
35
+
36
+ # Invokes 'lists.get_members' API method to retreive list members
37
+ #
38
+ # @param params [Hash] Params to be passed
39
+ # @return [Array] Array of Dashamail::Members instances
40
+ def get_members(params = {})
41
+ connection.call_method('lists.get_members', params.merge(id_params)).map {|member| Dashamail::Member.new(connection, member)}
42
+ end
43
+
44
+ # Alias to get_members
45
+ #
46
+ alias_method :members, :get_members
47
+
48
+ # Invokes 'lists.add_memner' method
49
+ #
50
+ # @param params [Hash] Params to be passed
51
+ # @return [Dashamail::Member] New member instance
52
+ def add_member(params)
53
+ added = connection.call_method('lists.add_member', params.merge(id_params))
54
+ get_members(added).first
55
+ end
56
+
57
+ # Invokes 'lists.unsubscribe_member' API method
58
+ #
59
+ # @param params [Hash] Params to be passed
60
+ # @return [Fixnum] Count of unsubscribed members
61
+ def unsubscribe_member(params)
62
+ connection.call_method('lists.unsubscribe_member', params.merge(id_params))['unsubscribed']
63
+ end
64
+
65
+ private
66
+
67
+ def id_params
68
+ {list_id: id}
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,70 @@
1
+ module Dashamail
2
+ class Member < Model
3
+ attr_reader :raw
4
+
5
+ FIELDS = [
6
+ :id,
7
+ :list_id,
8
+ :email,
9
+ :state,
10
+ :merge_1,
11
+ :merge_2,
12
+ :merge_3,
13
+ :merge_4,
14
+ :merge_5,
15
+ :optin_time,
16
+ :unsub_time,
17
+ :lastedit_time
18
+ ]
19
+
20
+ FIELDS.each do |f|
21
+ attr_reader f
22
+ end
23
+
24
+ # Initialize new member instance
25
+ #
26
+ # @param connection [Pachkin::Connection] Active connection
27
+ # @param doc [Hash] API object data
28
+ def initialize(connection, doc)
29
+ super(connection, doc)
30
+ FIELDS.each do |field|
31
+ instance_variable_set :"@#{field}", doc[field.to_s]
32
+ end
33
+ end
34
+
35
+ # Invokes 'lists.delete_member' API method
36
+ #
37
+ def delete_member
38
+ connection.call_method('lists.delete_member', id_params)
39
+ end
40
+
41
+ # Invokes 'lists.update_member' API method
42
+ #
43
+ # @param params [Hash] Params to be passed
44
+ def update_member(params)
45
+ connection.call_method('lists.update_member', params.merge(id_params))
46
+ end
47
+
48
+ # Invokes 'lists.get_lists' API method to retrieve member list
49
+ #
50
+ # @param params [Dashamail::List] List instance, accosiated with member
51
+ def list
52
+ connection.get_list(list_id)
53
+ end
54
+
55
+ # Invokes 'lists.unsubscribe_member' API method
56
+ #
57
+ # @param params [Hash] Params to be passed
58
+ # @return [Fixnum] Count of unsubscribed members
59
+ def unsubscribe_member(params)
60
+ connection.call_method('lists.unsubscribe_member', params.merge(id_params))['unsubscribed']
61
+ end
62
+
63
+ private
64
+
65
+ def id_params
66
+ {member_id: id}
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ module Dashamail
2
+ # Basic class for API model objects
3
+ class Model
4
+
5
+ # API object data
6
+ attr_reader :raw
7
+
8
+ # Initialize new model instance
9
+ #
10
+ # @param connection [Dashamail::Connection] Active connection
11
+ # @param doc [Hash] API object data
12
+ def initialize(connection, doc)
13
+ @connection = connection
14
+ @raw = doc
15
+ end
16
+
17
+ protected
18
+
19
+ def connection
20
+ @connection
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module DashaMailRb
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: DashaMailRb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexandr Prokopenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-15 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Interface for dashamail.ru service API
56
+ email:
57
+ - prokopenko@igc.ru
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".DS_Store"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - dashamailrb.gemspec
73
+ - lib/dashamailrb.rb
74
+ - lib/dashamailrb/api_exception.rb
75
+ - lib/dashamailrb/dashamail.rb
76
+ - lib/dashamailrb/list.rb
77
+ - lib/dashamailrb/member.rb
78
+ - lib/dashamailrb/model.rb
79
+ - lib/dashamailrb/version.rb
80
+ homepage: https://github.com/DashaMail/DashamailRb
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.5.2.3
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Interface for dashamail.ru service API
104
+ test_files: []