planethoster_api 0.0.2

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
+ SHA256:
3
+ metadata.gz: 6aafb84ca951dde1ebc416b4e3782c6f45b122d24c361e52b2ed30f8be9c2fff
4
+ data.tar.gz: 6e3b5f9cb3a5782c93f54761da5367e6ecd796de4a0c4a2e2a9a90d0d73e10af
5
+ SHA512:
6
+ metadata.gz: 5fabcd08c67baadfdcb8824991ad69e9b34452e390cb786395222c1796febe2a099447fe53bdfdf6c6f2d49c6609e1c36b0f6d7b54392059491b79224401176d
7
+ data.tar.gz: c1b67838dd4d1a357894685f3563d6b81837b40dad2a9ad1ae28dc6fc511b201c741acca3c9aeb61c0f24747a1f23465a64d806de278f06cf35ef3e129994508
data/.gitignore ADDED
@@ -0,0 +1,13 @@
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
12
+ .ruby-version
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.2
8
+ install: bundle
9
+ scripts: rake rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in planethoster_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 marcandreg
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,37 @@
1
+ [![Build Status](https://travis-ci.org/PlanetHoster/planethoster-node.svg?branch=master)](https://travis-ci.org/PlanetHoster/planethoster-node)
2
+
3
+ # Planethoster-ruby
4
+
5
+ PlanetHoster API gem is a work in progess
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'planethoster_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install planethoster_api
22
+
23
+ ## Usage
24
+
25
+ TODO
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
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PlanetHoster/planethoster-ruby/issues.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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 "planethoster_api"
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,20 @@
1
+ require 'utilities/api_client'
2
+
3
+ module PlanethosterApi
4
+ class ApiInterface
5
+ include Utilities
6
+
7
+ def initialize(api_user, api_key)
8
+ @api_client = ApiClient.new(api_user, api_key)
9
+ end
10
+
11
+ def test_connection
12
+ @api_client.call(
13
+ :get,
14
+ "/reseller-api/test-connection",
15
+ {}
16
+ )
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module PlanethosterApi
2
+ class Configuration
3
+ attr_accessor :api_user, :api_key
4
+
5
+ # Empty strings if not defined
6
+ def initialize
7
+ @api_user = ""
8
+ @api_key = ""
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ module PlanethosterApi
2
+ class Domain < ApiInterface
3
+
4
+ BASE_DOMAIN_PATH = '/reseller-api'
5
+
6
+ DOMAINS_METHODS_PATH = {
7
+ tld_prices: [:get, '/tld-prices'],
8
+ account_info: [:get, '/account-info'],
9
+ check_availability: [:get, '/check-availability'],
10
+ domain_info: [:get, '/domain-info'],
11
+ get_contact_details: [:get, '/get-contact-details'],
12
+ get_nameservers: [:get, '/get-nameservers'],
13
+ get_ph_dns_records: [:get, '/get-ph-dns-records'],
14
+ get_registrar_lock: [:get, '/get-registrar-lock '],
15
+ save_contact_details: [:post, '/save-contact-details'],
16
+ save_nameservers: [:post, '/save-nameservers'],
17
+ save_ph_dns_records: [:post, '/save-ph-dns-records'],
18
+ save_registrar_lock: [:post, '/save-registrar-lock'],
19
+ email_epp_copde: [:post, '/email-epp-code'],
20
+ register_domain: [:post, '/register-domain'],
21
+ renew_domain: [:post, '/renew-domain'],
22
+ transfer_domain: [:post, '/transfer-domain'],
23
+ delete_ph_dns_zone: [:post, '/delete-php-dns-zone']
24
+ }
25
+
26
+ DOMAINS_METHODS_PATH.each do |function_name, info|
27
+ method = info.first
28
+ path = "#{BASE_DOMAIN_PATH}#{info.last}"
29
+ params = params || {}
30
+
31
+ define_method(function_name) do |params|
32
+ @api_client.call(method, path, params)
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module PlanethosterApi
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,26 @@
1
+ module PlanethosterApi
2
+ class World < ApiInterface
3
+
4
+ BASE_WORLD_PATH = '/world-api'
5
+
6
+ WORLD_METHODS_PATH = {
7
+ get_accounts: [:get, '/get-accounts'],
8
+ create_account: [:post, '/create-account'],
9
+ suspend_account: [:post, '/suspend-account'],
10
+ unsuspend_account: [:post, '/unsuspend-account'],
11
+ modify_ressources: [:post, '/modify-ressources'],
12
+ upgrade_plan: [:post, '/upgrade-plan'],
13
+ }
14
+
15
+ WORLD_METHODS_PATH.each do |function_name, info|
16
+ method = info.first
17
+ path = "#{BASE_WORLD_PATH}#{info.last}"
18
+ params = params || {}
19
+
20
+ define_method(function_name) do |params|
21
+ @api_client.call(method, path, params)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ require 'planethoster_api/version'
2
+ require 'planethoster_api/configuration'
3
+ require 'planethoster_api/api_interface'
4
+ require 'planethoster_api/domain'
5
+ require 'planethoster_api/world'
6
+
7
+ module PlanethosterApi
8
+ class << self
9
+ attr_writer :configuration
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.reset
17
+ @configuration = Configuration.new
18
+ end
19
+
20
+ def self.configure
21
+ yield(configuration)
22
+ end
23
+
24
+ def self.domain
25
+ PlanethosterApi::Domain.new(
26
+ @configuration.api_user,
27
+ @configuration.api_key
28
+ )
29
+ end
30
+
31
+ def self.world
32
+ PlanethosterApi::World.new(
33
+ @configuration.api_user,
34
+ @configuration.api_key
35
+ )
36
+ end
37
+
38
+ end
@@ -0,0 +1,60 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ module Utilities
4
+ class ApiClient
5
+ include Net
6
+
7
+ BASE_URL='https://api.planethoster.net'
8
+
9
+ def initialize(api_user, api_key)
10
+ @headers = {
11
+ 'X_API_USER': api_user,
12
+ 'X_API_KEY': api_key,
13
+ 'content-type': 'text/json'
14
+ }
15
+ @uri = nil
16
+ @req = nil
17
+ @res = nil
18
+ end
19
+
20
+ def call(method, path, params)
21
+ @uri = URI.parse("#{BASE_URL}#{path}")
22
+ case method
23
+ when :get
24
+ get(params)
25
+ when :post
26
+ post(params)
27
+ else
28
+ {code: 405, error: "Method not allowed"}
29
+ end
30
+ end
31
+
32
+ private
33
+ def get(params)
34
+ @uri.query = URI.encode_www_form(params)
35
+ @req = HTTP::Get.new(@uri)
36
+ call!
37
+ end
38
+
39
+ def post(params)
40
+ @req = HTTP::Post.new(@uri)
41
+ @req.set_form(params)
42
+ call!
43
+ end
44
+
45
+ def call!
46
+ @headers.each do |k, v|
47
+ @req.add_field "#{k}", "#{v}"
48
+ end
49
+
50
+ @res = HTTP.start(@uri.hostname, @uri.port) {|http|
51
+ http.request(@req)
52
+ }
53
+
54
+ result = JSON.parse(@res.body)
55
+ result[:code] = @res.code
56
+
57
+ result
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "planethoster_api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "planethoster_api"
7
+ spec.version = PlanethosterApi::VERSION
8
+ spec.authors = ["marcandreg"]
9
+ spec.email = ["marc-andre.godin@planethoster.info"]
10
+
11
+ spec.summary = "PlanetHoster API wrapper"
12
+ spec.description = "Provide ruby gem for the PlanetHoster api's"
13
+ spec.homepage = "https://github.com/PlanetHoster/planethoster-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/PlanetHoster/planethoster-ruby"
18
+ spec.metadata["changelog_uri"] = "https://github.com/PlanetHoster/planethoster-ruby"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: planethoster_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - marcandreg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-14 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: Provide ruby gem for the PlanetHoster api's
56
+ email:
57
+ - marc-andre.godin@planethoster.info
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/planethoster_api.rb
72
+ - lib/planethoster_api/api_interface.rb
73
+ - lib/planethoster_api/configuration.rb
74
+ - lib/planethoster_api/domain.rb
75
+ - lib/planethoster_api/version.rb
76
+ - lib/planethoster_api/world.rb
77
+ - lib/utilities/api_client.rb
78
+ - planethoster_api.gemspec
79
+ homepage: https://github.com/PlanetHoster/planethoster-ruby
80
+ licenses:
81
+ - MIT
82
+ metadata:
83
+ homepage_uri: https://github.com/PlanetHoster/planethoster-ruby
84
+ source_code_uri: https://github.com/PlanetHoster/planethoster-ruby
85
+ changelog_uri: https://github.com/PlanetHoster/planethoster-ruby
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.0.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: PlanetHoster API wrapper
105
+ test_files: []