scalingo-provider_api 0.1.5

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: c4e698a5d131e76663c70ab7420a89ce3daaac0c
4
+ data.tar.gz: ec810ccff9875d804f0b22a847851593cfa8cb7e
5
+ SHA512:
6
+ metadata.gz: 622504f3d66a042ad4d68a7a7185421db13fd0f584bb84882811664169aca664031a2b7b20cadc56a5864aeb8e048c346daf8662ba571fe0cf49541e2354ad1c
7
+ data.tar.gz: 8ca6b93a36826aec364d93624c8a6c0ef2f39943bbb086d94e324f07c66b6ab230875af5cce0dc4555cabc4760ef73c82f5fc7486f304fd0a4351e80a5f79701
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # Compiled gems
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
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 scalingo-provider_api.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jonathan Hurter
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,60 @@
1
+ # Scalingo::ProviderApi
2
+
3
+ Ruby client for the Scalingo provider API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'scalingo-provider_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scalingo-provider_api
20
+
21
+ ## Usage
22
+
23
+
24
+ ### Intialization
25
+
26
+ ```ruby
27
+ client = Scalingo::ProviderApi::Client.new("user", "password")
28
+ ```
29
+
30
+ ### Find an app by id
31
+
32
+ ```ruby
33
+ app = client.find_app "resource_id"
34
+ ```
35
+
36
+ ### Send configuration for an addon
37
+
38
+ ```ruby
39
+ client.send_config "resource_id", {ENV_1: "VALUE", ENV_2: "VALUE2"}
40
+ ```
41
+
42
+ ### Provision an addon
43
+
44
+ ```ruby
45
+ client.provision "resource_id"
46
+ ```
47
+
48
+ ## Development
49
+
50
+ 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.
51
+
52
+ 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).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Scalingo/scalingo-provider_api.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://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,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "scalingo/provider_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
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,79 @@
1
+ require 'scalingo/provider_api/version'
2
+ require 'faraday'
3
+ require 'json'
4
+
5
+ module Scalingo
6
+ module ProviderApi
7
+ class Client
8
+ API_BASE_URL = 'https://api.scalingo.com/'.freeze
9
+
10
+ # Will define methods. The method will use the key as a name,
11
+ # and will be configured with the value.
12
+ #
13
+ # Value desc:
14
+ # * method: HTTP method to call
15
+ # * path: Parametrized url to call
16
+ # Parameters can must be valid with the following regex: /:[a-z_]+/
17
+ # The method will use arguments in the order of appeareance in the url
18
+ # * body: should this method accept a body?
19
+ # * body_hook; lambda function that will transform the body
20
+ METHODS = {
21
+ find_app: { method: :get, path: '/v1/provider/apps/:resource_id' },
22
+ send_config: { method: :patch, path: '/v1/provider/addons/:resource_id/config', body: true, body_hook: lambda {|b| {config: b}}},
23
+ provision: { method: :post, path: '/v1/provider/addons/:resource_id/actions/provision' }
24
+ }.freeze
25
+
26
+ def initialize(user, password, args = {})
27
+ @user = user
28
+ @password = password
29
+
30
+ @base_url = API_BASE_URL
31
+ @base_url = args[:base_url] if !args[:base_url].nil?
32
+ end
33
+
34
+ def method_missing(met, *a)
35
+ return if METHODS[met].nil?
36
+ desc = METHODS[met]
37
+ path = desc[:path]
38
+
39
+ # Find all arguments.
40
+ # http://a.fr/:a/b/:c/:a => [:a, :c]
41
+ args = path.scan(/:[a-z_]+/).uniq
42
+
43
+ # If we need a body add :body to the list of arguments
44
+ args << ":body" if desc[:body]
45
+
46
+ raise "Invalid arg count: #{a.length}, expected: #{args.length}" if args.length != a.length
47
+
48
+ args.each_with_index do |name, index|
49
+ old_name = name
50
+ name="@#{name[1..-1]}" # :abc => @abc
51
+
52
+ # Set an instance variable with the arg name
53
+ self.instance_variable_set name.to_s, a[index]
54
+
55
+ if name != "@body"
56
+ # Replace the variable name with its value in the path
57
+ path = path.gsub(old_name.to_s, self.instance_variable_get(name))
58
+ end
59
+ end
60
+
61
+ conn = Faraday.new url: @base_url do |c|
62
+ c.basic_auth(@user, @password)
63
+
64
+ c.use Faraday::Response::RaiseError
65
+ c.use Faraday::Adapter::NetHttp
66
+ end
67
+
68
+ @body = desc[:body_hook].call @body if !desc[:body_hook].nil?
69
+
70
+ res = conn.send(desc[:method], path) do |req|
71
+ req.headers['Content-Type'] = 'application/json'
72
+ req.options.timeout = 30
73
+ req.body = @body.to_json
74
+ end
75
+ return JSON.parse res.body
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ module Scalingo
2
+ module ProviderApi
3
+ VERSION = "0.1.5"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "scalingo/provider_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scalingo-provider_api"
8
+ spec.version = Scalingo::ProviderApi::VERSION
9
+ spec.authors = ["Jonathan Hurter"]
10
+ spec.email = ["john@scalingo.com"]
11
+
12
+ spec.summary = %q{Communication between a provider and Scalingo}
13
+ spec.description = %q{A gem that implement the basic method to communicate between an addon provider and the Scalingo API}
14
+ spec.homepage = "https://github.com/Scalingo/scalingo-provider-api-gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 12.1"
26
+ spec.add_development_dependency "rspec", "~> 3.6"
27
+ spec.add_development_dependency "webmock", "~> 3.1"
28
+ spec.add_development_dependency "pry", "~> 0.10"
29
+
30
+ spec.add_dependency "faraday", "~> 0.13.1"
31
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scalingo-provider_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Hurter
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-09 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: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.1'
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.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.13.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.13.1
97
+ description: A gem that implement the basic method to communicate between an addon
98
+ provider and the Scalingo API
99
+ email:
100
+ - john@scalingo.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/scalingo/provider_api.rb
114
+ - lib/scalingo/provider_api/version.rb
115
+ - scalingo-provider_api.gemspec
116
+ homepage: https://github.com/Scalingo/scalingo-provider-api-gem
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.6.11
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Communication between a provider and Scalingo
140
+ test_files: []