improvmx 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d7859f7b94f30a8fd712321821172498e179e1de7a8a5e893e46a3f131339b1
4
- data.tar.gz: c468089b24a881419a854ef0cb2ef7597342f77789304f61293d2b1ff1e134dd
3
+ metadata.gz: 1beb2bc2f4cde29fb6ad32bf378c9ec8df1e9038e182af63d52cf825b9ef040a
4
+ data.tar.gz: b94c1f17643079e3b8db5392099d3983780e2a9d2efd31d00e52fe92ae8c3de1
5
5
  SHA512:
6
- metadata.gz: 54a26c1b99e2eb1136b07d12026b5ffb73fd5900fd61d7658a634d71e711cc8535741f8c6f4756012b8e114246768a712f13445fef809bd6d1c2726b228a08f1
7
- data.tar.gz: eed54722a9f29bbaa8d1c7c73b60184d95ec1af7ea13c41e786ff9074d0b30e36f6979eccaf149f8c104cf833147f1fc2944c9eddd1b8af0d0190c21f11e0ace
6
+ metadata.gz: c59717e47ade074c19e188e6e8106d125e2245097851a65347980dfcfda30eab9c25f429242bc53b69b5d32e6d180b60ddcc9e30bd466048b75af36bebb4d672
7
+ data.tar.gz: 32a7c975cef2ad65c894de582b2b33e15dfc01fd8bb84fe580f149018f606abf7758ef2313985a17c8c8b1841abe97656c86378625a0841bcadba563ada5b147
data/README.md CHANGED
@@ -21,14 +21,28 @@ This is how you can use this gem
21
21
  require 'improvmx'
22
22
 
23
23
  # Instantiate the Client with your API key and domain
24
- client = Improvmx::Client.new 'your-api-key', 'domain.com'
24
+ client = Improvmx::Client.new 'your-api-key'
25
25
 
26
26
  # List all the aliases
27
- aliases = client.list_aliases
27
+ aliases = client.list_aliases('domain.com')
28
28
 
29
29
  puts aliases['aliases']
30
30
  ```
31
31
 
32
+ Improvmx has a rate limit system, to handle this you can do
33
+ ```ruby
34
+ require 'improvmx'
35
+ client = Improvmx::Client.new 'your-api-key'
36
+
37
+ begin
38
+ client.list_aliases('domain.com')
39
+ rescue Improvmx::RateLimitError => e
40
+ sleep e.wait_seconds
41
+ retry
42
+ end
43
+
44
+ ```
45
+
32
46
  Rails
33
47
  -----
34
48
 
@@ -64,4 +78,4 @@ This part is for maintaincers only. In order to deploy this gem to rubygem follo
64
78
 
65
79
  1. Bump the version in `lib/improvmx/version.rb`
66
80
  1. Build the gem using `gem build improvmx.gemspec`
67
- 1.
81
+ 1. Push it to rubygems `gem push improvmx-x.x.x.gem`
data/improvmx.gemspec CHANGED
@@ -16,5 +16,5 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = %w[lib]
17
17
 
18
18
  spec.required_ruby_version = '>= 2.4'
19
- spec.add_dependency 'rest-client', '>= 2.0.2'
19
+ spec.add_dependency 'rest-client', '~> 2.0'
20
20
  end
data/lib/improvmx.rb CHANGED
@@ -8,7 +8,7 @@ require 'improvmx/exceptions/exceptions'
8
8
  # Module for interaction with Improvmx
9
9
  module Improvmx
10
10
  class << self
11
- attr_accessor :api_key, :domain
11
+ attr_accessor :api_key
12
12
 
13
13
  def configure
14
14
  yield self
@@ -1,23 +1,23 @@
1
1
  module Improvmx
2
2
  # All alias related endpoints
3
3
  module Aliases
4
- def list_aliases(params = {})
4
+ def list_aliases(domain, params = {})
5
5
  get("/domains/#{domain}/aliases/", params).to_h
6
6
  end
7
7
 
8
- def get_alias(alias_name)
8
+ def get_alias(alias_name, domain)
9
9
  get("/domains/#{domain}/aliases/#{alias_name}")
10
10
  rescue NotFoundError
11
11
  nil
12
12
  end
13
13
 
14
- def create_alias(alias_name, forward_to)
14
+ def create_alias(alias_name, forward_to, domain)
15
15
  response = post("/domains/#{domain}/aliases/", { alias: alias_name, forward: forward(forward_to) })
16
16
 
17
17
  response.ok?
18
18
  end
19
19
 
20
- def update_alias(alias_name, forward_to)
20
+ def update_alias(alias_name, forward_to, domain)
21
21
  response = put("/domains/#{domain}/aliases/#{alias_name}", { forward: forward(forward_to) })
22
22
 
23
23
  response.ok?
@@ -25,13 +25,12 @@ module Improvmx
25
25
  false
26
26
  end
27
27
 
28
- def create_or_update_alias(alias_name, forward_to)
29
- create_alias(alias_name, forward_to)
30
- rescue BadRequestError
31
- update_alias(alias_name, forward_to)
28
+ def create_or_update_alias(alias_name, forward_to, domain)
29
+ return true if update_alias(alias_name, forward_to, domain)
30
+ create_alias(alias_name, forward_to, domain)
32
31
  end
33
32
 
34
- def delete_alias(alias_name)
33
+ def delete_alias(alias_name, domain)
35
34
  response = delete("/domains/#{domain}/aliases/#{alias_name}")
36
35
 
37
36
  response.ok?
@@ -8,7 +8,7 @@ module Improvmx
8
8
  include Improvmx::Aliases
9
9
  include Improvmx::Utils
10
10
 
11
- def initialize(api_key = Improvmx.api_key, domain = Improvmx.domain)
11
+ def initialize(api_key = Improvmx.api_key)
12
12
  rest_client_params = {
13
13
  user: 'api',
14
14
  password: api_key,
@@ -16,17 +16,8 @@ module Improvmx
16
16
  }
17
17
 
18
18
  @http_client = RestClient::Resource.new('https://api.improvmx.com/v3', rest_client_params)
19
- @domain = domain
20
19
  end
21
20
 
22
- # Generic Improvmx POST Handler
23
- #
24
- # @param [String] resource_path This is the API resource you wish to interact
25
- # with. Be sure to include your domain, where necessary.
26
- # @param [Hash] data This should be a standard Hash
27
- # containing required parameters for the requested resource.
28
- # @param [Hash] headers Additional headers to pass to the resource.
29
- # @return [Improvmx::Response] A Improvmx::Response object.
30
21
  def post(resource_path, data, headers = {})
31
22
  response = @http_client[resource_path].post(data, headers)
32
23
  Response.new(response)
@@ -34,14 +25,6 @@ module Improvmx
34
25
  raise communication_error e
35
26
  end
36
27
 
37
- # Generic Improvmx GET Handler
38
- #
39
- # @param [String] resource_path This is the API resource you wish to interact
40
- # with.
41
- # @param [Hash] params This should be a standard Hash
42
- # containing required parameters for the requested resource.
43
- # @param [String] accept Acceptable Content-Type of the response body.
44
- # @return [Improvmx::Response] A Improvmx::Response object.
45
28
  def get(resource_path, params = nil, accept = '*/*')
46
29
  response = @http_client[resource_path].get(params: params, accept: accept)
47
30
  Response.new(response)
@@ -49,13 +32,6 @@ module Improvmx
49
32
  raise communication_error e
50
33
  end
51
34
 
52
- # Generic Improvmx PUT Handler
53
- #
54
- # @param [String] resource_path This is the API resource you wish to interact
55
- # with.
56
- # @param [Hash] data This should be a standard Hash
57
- # containing required parameters for the requested resource.
58
- # @return [Improvmx::Response] A Improvmx::Response object.
59
35
  def put(resource_path, data)
60
36
  response = @http_client[resource_path].put(data)
61
37
  Response.new(response)
@@ -63,11 +39,6 @@ module Improvmx
63
39
  raise communication_error e
64
40
  end
65
41
 
66
- # Generic Improvmx DELETE Handler
67
- #
68
- # @param [String] resource_path This is the API resource you wish to interact
69
- # with.
70
- # @return [Improvmx::Response] A Improvmx::Response object.
71
42
  def delete(resource_path)
72
43
  response = @http_client[resource_path].delete
73
44
  Response.new(response)
@@ -75,13 +46,8 @@ module Improvmx
75
46
  raise communication_error e
76
47
  end
77
48
 
78
- attr_reader :domain
79
-
80
49
  private
81
50
 
82
- # Raises CommunicationError and stores response in it if present
83
- #
84
- # @param [StandardException] e upstream exception object
85
51
  def communication_error(e) # rubocop:disable Metrics/AbcSize
86
52
  if e.respond_to? :response
87
53
  code = e.response.code
@@ -1,3 +1,3 @@
1
1
  module Improvmx
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: improvmx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - C.S.V. Alpha
@@ -15,16 +15,16 @@ dependencies:
15
15
  name: rest-client
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.0.2
20
+ version: '2.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 2.0.2
27
+ version: '2.0'
28
28
  description: Ruby interface for the ImprovMX API
29
29
  email: ict@csvalpha.nl
30
30
  executables: []
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.0.8
63
+ rubygems_version: 3.2.14
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Ruby interface for the ImprovMX API