oma-ruby 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: 0f0bd40530f84539309649bc84ab16f8d5ccba77
4
+ data.tar.gz: baba61dd76d77128dbab50d882f6f780b502d5c8
5
+ SHA512:
6
+ metadata.gz: d9051716cd3aad70618183d316a3bc3a8c1f8504239f1b6820e75715214ce2975837377906c15dfca780afa919706355832eea91c550efccd3f382cedbc18a30
7
+ data.tar.gz: daca8c5674093fb4397b9997b2939939474d0fcd2007d4d2659e3ecfa6222f4603fbd2bea3f46e78aa7f3bd0f5c0ce64fdbd91b9c287a6b35fbe5b245f2d0de4
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/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in oma.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oma-ruby (0.1.0)
5
+ faraday (~> 0.15)
6
+ faraday_middleware (~> 0.12)
7
+ oj (~> 3.7)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.2)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ crack (0.4.2)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ faraday (0.15.4)
18
+ multipart-post (>= 1.2, < 3)
19
+ faraday_middleware (0.12.2)
20
+ faraday (>= 0.7.4, < 1.0)
21
+ multipart-post (2.0.0)
22
+ oj (3.7.1)
23
+ public_suffix (3.0.3)
24
+ rake (10.4.2)
25
+ rspec (3.7.0)
26
+ rspec-core (~> 3.7.0)
27
+ rspec-expectations (~> 3.7.0)
28
+ rspec-mocks (~> 3.7.0)
29
+ rspec-core (3.7.1)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-expectations (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-mocks (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-support (3.7.0)
38
+ safe_yaml (1.0.4)
39
+ webmock (1.20.4)
40
+ addressable (>= 2.3.6)
41
+ crack (>= 0.3.2)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.16)
48
+ oma-ruby!
49
+ rake (~> 10.0)
50
+ rspec (~> 3.0)
51
+ webmock (~> 1.20)
52
+
53
+ BUNDLED WITH
54
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 ousmane
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,39 @@
1
+ # Oma Ruby
2
+ The Oma Ruby library provides convenient access to the Open SRS Mail API from applications written in the Ruby language.
3
+
4
+ See the [OpenSRS Mail API](https://opensrs.com/wp-content/uploads/OpenSRS_Mail_API.pdf).
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'oma-ruby'
11
+ ```
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install oma-ruby
19
+
20
+ ## Requirements
21
+ * Ruby 2.0+.
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'oma-ruby'
27
+
28
+ oma_client = Oma::Ruby::Client.new(
29
+ url: 'https://mail.test.hostedemail.com/api',
30
+ user: 'admin@companydomain.com',
31
+ password: 'company_password'
32
+ )
33
+
34
+ oma_client.change_user(
35
+ user: 'john@example.com',
36
+ password: 'p@ssword',
37
+ name: 'John Doe'
38
+ )
39
+ ```
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 "oma"
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,57 @@
1
+ module Oma
2
+ module Ruby
3
+ module Actions
4
+ API_ACTIONS = %w[
5
+ authenticate
6
+ change_company
7
+ change_company_bulletin
8
+ echo
9
+ get_company
10
+ get_company_bulletin
11
+ get_company_changes
12
+ post_company_bulletin
13
+ search_admins
14
+ change_domain
15
+ change_domain_bulletin
16
+ delete_domain
17
+ get_domain
18
+ get_domain_bulletin
19
+ get_domain_changes
20
+ post_domain_bulletin
21
+ restore_domain
22
+ search_domains
23
+ create_workgroup
24
+ delete_workgroup
25
+ search_workgroups
26
+ change_user
27
+ delete_user
28
+ generate_token
29
+ get_deleted_contacts
30
+ get_deleted_messages
31
+ get_user
32
+ get_user_attribute_history
33
+ get_user_changes
34
+ get_user_folders
35
+ get_user_messages
36
+ logout_user
37
+ move_user_messages
38
+ reindex
39
+ rename_user
40
+ restore_deleted_contacts
41
+ restore_deleted_messages
42
+ restore_user
43
+ search_users
44
+ set_role
45
+ user_notify
46
+ search_brands
47
+ stats_list
48
+ stats_snapshot
49
+ stats_summary
50
+ migration_add
51
+ migration_jobs
52
+ migration_status
53
+ migration_trace
54
+ ].freeze
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,72 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'oj'
4
+
5
+ module Oma
6
+ # Client implementation
7
+ module Ruby
8
+ # Client class
9
+ class Client
10
+ attr_reader :url, :user, :password
11
+
12
+ include Errors
13
+ include Actions
14
+
15
+ def initialize(url:, user:, password:)
16
+ @url = url
17
+ @user = user
18
+ @password = password
19
+ end
20
+
21
+ API_ACTIONS.each do |action|
22
+ define_method(action) do |params = nil|
23
+ request(action, params || {})
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def api
30
+ @api ||= Faraday.new(url: url) do |connection|
31
+ connection.request :json
32
+ connection.adapter Faraday.default_adapter
33
+ end
34
+ end
35
+
36
+ def request(action, params)
37
+ response = api.post(action, format_params(params))
38
+
39
+ handle_reponse(response)
40
+ end
41
+
42
+ def handle_reponse(response)
43
+ check_http_error!(response)
44
+ check_api_error!(response)
45
+
46
+ Oj.load(response.body)
47
+ end
48
+
49
+ def check_http_error!(response)
50
+ return if response.status == 200
51
+
52
+ raise http_error(response.status)
53
+ end
54
+
55
+ def check_api_error!(response)
56
+ body = Oj.load(response.body)
57
+
58
+ return if body['success']
59
+
60
+ raise api_error(body['error_number']), body['error']
61
+ end
62
+
63
+ def api_credentials
64
+ @api_credentials ||= { user: user, password: password }
65
+ end
66
+
67
+ def format_params(params)
68
+ { credentials: api_credentials }.merge(params)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,56 @@
1
+ module Oma
2
+ # HTTP and API Errors mapping
3
+ module Ruby
4
+ # Errors module
5
+ module Errors
6
+ class HttpError < StandardError; end
7
+ class OpenSRSApiError < StandardError; end
8
+
9
+ HTTP_ERRORS = {
10
+ '400' => 'BadRequestError',
11
+ '404' => 'NotFoundError',
12
+ '500' => 'InternalServerError'
13
+ }.freeze
14
+
15
+ API_ERRORS = {
16
+ '0' => 'ServerError',
17
+ '1' => 'InvalidCredentialsError',
18
+ '2' => 'RequestedObjectDoesNotExistError',
19
+ '3' => 'ObjectIsAliasError',
20
+ '4' => 'RequestorLacksPermissionError',
21
+ '5' => 'RequestBadlyFormattedError',
22
+ '6' => 'AttributesBadlyFormattedError',
23
+ '7' => 'ObjectAlreadyExistsError',
24
+ '8' => 'DomainDoesNotExistError',
25
+ '9' => 'RequestorDoesNotOwnObjectError',
26
+ '10' => 'RequestedObjectNotEmptyError',
27
+ '11' => 'CompanyDoesNotExistError',
28
+ '12' => 'RoleDoesNotExistError',
29
+ '13' => 'UserDoesNotExistError',
30
+ '14' => 'BrandInUseError',
31
+ '15' => 'DomainUsersFullError',
32
+ '16' => 'DomainAliasesFullError',
33
+ '17' => 'NotInError',
34
+ '18' => 'WorkgroupIsDefaultError',
35
+ '19' => 'MigrationJobExistsError',
36
+ '20' => 'TryAgainLaterError'
37
+ }.freeze
38
+
39
+ HTTP_ERRORS.each_value do |error|
40
+ const_set(error, Class.new(HttpError))
41
+ end
42
+
43
+ API_ERRORS.each_value do |error|
44
+ const_set(error, Class.new(OpenSRSApiError))
45
+ end
46
+
47
+ def http_error(status)
48
+ Oma::Ruby::Errors.const_get(HTTP_ERRORS.fetch(status.to_s, 'HttpError'))
49
+ end
50
+
51
+ def api_error(code)
52
+ Oma::Ruby::Errors.const_get(API_ERRORS.fetch(code.to_s, 'OpenSRSApiError'))
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ module Oma
2
+ module Ruby
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
data/lib/oma-ruby.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'oma-ruby/version'
2
+ require 'oma-ruby/errors'
3
+ require 'oma-ruby/actions'
4
+ require 'oma-ruby/client'
5
+
6
+ module Oma
7
+ # Main module
8
+ module Ruby
9
+ end
10
+ end
data/oma-ruby.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "oma-ruby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "oma-ruby"
7
+ spec.version = Oma::Ruby::VERSION
8
+ spec.authors = ["Rahmane Ousmane"]
9
+ spec.email = ["ousmanedev@gmail.com"]
10
+
11
+ spec.summary = %q{OpenSrs Mail API}
12
+ spec.description = %q{Ruby Gem to utilize the OpenSRS MAIL API}
13
+ spec.homepage = "https://github.com/ousmanedev/oma"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "faraday", "~> 0.15"
24
+ spec.add_runtime_dependency "faraday_middleware", "~> 0.12"
25
+ spec.add_runtime_dependency "oj", "~> 3.7"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "webmock", "~> 1.20"
31
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oma-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rahmane Ousmane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oj
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.20'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.20'
111
+ description: Ruby Gem to utilize the OpenSRS MAIL API
112
+ email:
113
+ - ousmanedev@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/oma-ruby.rb
128
+ - lib/oma-ruby/actions.rb
129
+ - lib/oma-ruby/client.rb
130
+ - lib/oma-ruby/errors.rb
131
+ - lib/oma-ruby/version.rb
132
+ - oma-ruby.gemspec
133
+ homepage: https://github.com/ousmanedev/oma
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.5
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: OpenSrs Mail API
157
+ test_files: []