cloud_party 0.1.0.pre.pre.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.
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ bundler_args: --jobs=6 --retry=3 --standalone
3
+ script:
4
+ - echo "Running tests against $(ruby -v) ..."
5
+ - bundle exec rake -t
6
+ rvm:
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+
@@ -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, ethnicity, 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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ # Specify your gem's dependencies in cloud_party.gemspec
5
+ gemspec
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ken Spencer
4
+ Copyright (c) 2015 Trevor Wistaff
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -0,0 +1,144 @@
1
+ [![Gem Version](https://badge.fury.io/rb/cloud_party.svg)](https://badge.fury.io/rb/cloud_party)
2
+ [![Code Climate](https://codeclimate.com/github/IotaSpencer/cloud_party/badges/gpa.svg)](https://codeclimate.com/github/IotaSpencer/cloud_party)
3
+ [![Test Coverage](https://codeclimate.com/github/IotaSpencer/cloud_party/badges/coverage.svg)](https://codeclimate.com/github/IotaSpencer/cloud_party/coverage)
4
+ [![Build Status](https://travis-ci.org/IotaSpencer/cloud_party.svg?branch=master)](https://travis-ci.org/IotaSpencer/cloud_party)
5
+ # CloudParty
6
+
7
+ Super thin Ruby wrapper for Cloudflare's V4 API.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'cloud_party'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```shell
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```shell
26
+ $ gem install cloud_party
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ First off, open https://api.cloudflare.com/ to see all the available endpoints
32
+
33
+ ### Quick start
34
+
35
+ #### Setup connection
36
+
37
+ Two configurations are applicable for setup currently,
38
+
39
+
40
+ <details>
41
+ <summary>$HOME/.cloud_party/config or /etc/cloud_party/config</summary>
42
+ <p markdown="1">
43
+
44
+ ```yaml
45
+ email: 'email@here.com'
46
+ api-key: 'abcdefabcdef1234561234567890'
47
+ ```
48
+ </p>
49
+ </details>
50
+
51
+ ```ruby
52
+ require 'cloud_party'
53
+ connection = CloudParty.connect
54
+ ```
55
+
56
+ #### GET your user account details
57
+
58
+ ```ruby
59
+ user = connection.get('user')
60
+
61
+ # Read the first result
62
+ p user.result
63
+
64
+ # Read your first name
65
+ p user.result[:first_name]
66
+ ```
67
+
68
+ #### Update(PATCH) your user account
69
+
70
+ ```ruby
71
+ user = connection.patch('user', { first_name: 'Bear' })
72
+
73
+ # Read the first result
74
+ p user.result
75
+ ```
76
+
77
+ #### GET all your zones
78
+
79
+ ```ruby
80
+ zones = connection.get('zones')
81
+
82
+ # Read the first zone
83
+ p zones.result
84
+
85
+ # Read the array of zones. Pluralize #result
86
+ p zones.results
87
+ ```
88
+
89
+ #### Create(POST) a new zone (domain)
90
+
91
+ ```ruby
92
+ zone = connection.post('zones', { name: 'supercooldomain.com' })
93
+
94
+ # Check it out
95
+ p zone.result
96
+ ```
97
+
98
+ #### Add(POST) an A Record to the zone
99
+
100
+ ```ruby
101
+ dns_record = connection.post('zones/{#zone.result[:id]}/dns_records', {
102
+ type: 'A',
103
+ name: 'supercooldomain.com',
104
+ content: '127.0.0.1'
105
+ })
106
+
107
+ # Check it out
108
+ p dns_record.result
109
+ ```
110
+
111
+ #### DELETE a zone
112
+
113
+ ```ruby
114
+ deleted_zone = connection.delete('zones/#{zone.result[:id]}')
115
+
116
+ # Check out the response
117
+ p deleted_zone
118
+ ```
119
+
120
+ #### Catch errors
121
+
122
+ ```ruby
123
+ begin
124
+ connection.get('user')
125
+ rescue => e
126
+ # Inspect e.reponse for more details
127
+ p e.response
128
+ end
129
+ ```
130
+
131
+ ## Development
132
+
133
+ 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.
134
+
135
+ 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).
136
+
137
+ ## Contributing
138
+
139
+ Bug reports and pull requests are welcome on GitHub at https://github.com/trev/rubyflare. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
140
+
141
+
142
+ ## License
143
+
144
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task default: :test
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'cloud_party'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
13
+
14
+ # require "irb"
15
+ # 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,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'cloud_party/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'cloud_party'
9
+ spec.version = CloudParty::VERSION
10
+ spec.authors = ['Ken Spencer', 'Trevor Wistaff']
11
+ spec.email = ['me+gems@iotaspencer.me', 'trev@a07.com.au']
12
+
13
+ spec.summary = "Thin Ruby wrapper around Cloudflare's V4 API. Based on https://github.com/trev/rubyflare"
14
+ spec.description = "Thin Ruby wrapper around Cloudflare's V4 API for good measure!"
15
+ spec.homepage = 'https://github.com/IotaSpencer/cloud_party'
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 = 'bin'
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = %w[lib]
22
+
23
+ # spec.required_ruby_version = '>= 2.3'
24
+ spec.add_development_dependency 'bundler', '~> 1.17.2'
25
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6.0'
26
+ spec.add_development_dependency 'debase'
27
+ spec.add_development_dependency 'pry', '~> 0.11.3'
28
+ spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.1'
29
+ spec.add_development_dependency 'rspec', '~> 3.5'
30
+ spec.add_development_dependency 'ruby-debug-ide', '~> 0.7.0.beta7'
31
+ spec.add_development_dependency 'webmock', '~> 2.1'
32
+
33
+ spec.add_runtime_dependency 'app_configuration'
34
+ spec.add_runtime_dependency 'httparty', '~> 0.16.2'
35
+ spec.add_runtime_dependency 'rubyflare'
36
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/version'
4
+ require 'cloud_party/context'
5
+ require 'cloud_party/response'
6
+ require 'cloud_party/responses'
7
+ require 'cloud_party/exceptions'
8
+ require 'cloud_party/nodes'
9
+ require 'cloud_party/simple'
10
+
11
+ require 'httparty'
12
+ require 'json'
13
+ require 'app_configuration'
14
+ class Hash
15
+ #take keys of hash and transform those to a symbols
16
+ def self.transform_keys_to_symbols(value)
17
+ return value if not value.is_a?(Hash)
18
+ hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = Hash.transform_keys_to_symbols(v); memo}
19
+ return hash
20
+ end
21
+ end
22
+ class String
23
+ def squish!
24
+ strip!
25
+ gsub!(/\s+/, ' ')
26
+ self
27
+ end
28
+
29
+ def squish
30
+ dup.squish!
31
+ end
32
+ end
33
+ module CloudParty
34
+ def self.simple_connect
35
+ CloudParty::Simple.new.connect
36
+ end
37
+ def self.context_connect
38
+ CloudParty::Context.new
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'app_configuration'
4
+ module CloudParty
5
+ class Config
6
+ def initialize
7
+ cp_config = AppConfiguration.new('config') do
8
+ base_local_path Pathname.new(Dir.home).join('.cloud_party/')
9
+ base_global_path Pathname.new(Etc.sysconfdir).join('cloud_party')
10
+ use_env_variables true
11
+ prefix 'cloud_party'
12
+ end
13
+ cfcli_config = AppConfiguration.new('config') do
14
+ base_local_path Pathname.new(Dir.home).join('.cfcli/')
15
+ base_global_path Pathname.new(Etc.sysconfdir).join('cloudflare_cli')
16
+ use_env_variables true
17
+ prefix 'cf_cli'
18
+ end
19
+ @email = cp_config.email || cfcli_config.email
20
+ @api_key = cp_config.api_key || cfcli_config.api_key
21
+ end
22
+
23
+ # @return [String] the email string
24
+ def email
25
+ @email
26
+ end
27
+
28
+ # @return [String] the api key string
29
+ def api_key
30
+ @api_key
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'cloud_party/config'
5
+ module CloudParty
6
+ class Context
7
+ attr_reader :cfg
8
+ define_singleton_method(:cfg) do
9
+ CloudParty::Config.new
10
+ end
11
+ def self.inherited(subclass)
12
+ # I don't know yet
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudParty
4
+ class ConnectionError < StandardError
5
+ attr_reader :response
6
+
7
+ def initialize(message, response)
8
+ super(message)
9
+ @response = response
10
+ end
11
+ end
12
+
13
+ class APIError < StandardError
14
+ attr_reader(:response)
15
+ def initialize(message, response)
16
+ super(message)
17
+ @response = response
18
+ end
19
+ end
20
+ class RequestError < StandardError
21
+ def initialize(obj:, method:, code:, response:, endpoint:)
22
+ @obj = obj
23
+ @method = method
24
+ @endpoint = endpoint
25
+ @code = code
26
+ @response = response
27
+ end
28
+
29
+ def to_s
30
+ [error_string.squish, extra_string].join("\n")
31
+ end
32
+
33
+ def self.extra_string; end
34
+
35
+ def self.error_string; end
36
+ end
37
+ class UnknownError < RequestError
38
+ def initialize(obj:, method:, response:, endpoint: nil, code:)
39
+ super
40
+ end
41
+
42
+ def self.error_string
43
+ <<~HEREDOC
44
+ An error with the request has occurred, please make
45
+ sure the method verb, endpoint, and credentials are
46
+ correct for this request.
47
+ HEREDOC
48
+ end
49
+
50
+ def self.extra_string
51
+ <<~HEREDOC
52
+ Credentials Context: #{@obj&.class&.cfg}
53
+
54
+ Method Verb: #{@method}
55
+ Endpoint: #{@endpoint}
56
+ HTTP Status Code: #{@code}
57
+ Response Body: #{@response.body}
58
+ HEREDOC
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ autoload :BadRequestError, 'cloud_party/exceptions/bad_request_400'
6
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloud_party/exception'
4
+ module CloudParty
5
+ # Request was invalid
6
+ class BadRequest < RequestError
7
+ def initialize(obj:, method:, response:, endpoint: nil, code: 400)
8
+ super
9
+ end
10
+
11
+ def self.error_string
12
+ <<~HEREDOC
13
+ There was a '400 -- Bad Request' error.
14
+ HEREDOC
15
+ end
16
+
17
+ def self.extra_string
18
+ <<~HEREDOC
19
+ VERB: #{@method}
20
+
21
+ HEREDOC
22
+ end
23
+ end
24
+ end