kc-sdk-app 0.2.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
+ SHA256:
3
+ metadata.gz: de3af01fb20a50fbc26e6d78cb0d95693cca7deede1563146bdc4b03cae69de0
4
+ data.tar.gz: c743a784bc692abbf836afb0f3a2cceb8489df71255c994b593704d5c4382921
5
+ SHA512:
6
+ metadata.gz: e42c164217f055843665eefc440e28d30ef5a039c43ffed613b7619af65665987c83479de62b53012176f1dc7d6cd242c94bdb62a0524daef38fdc4f714c2eb7
7
+ data.tar.gz: 75a5228b41710399b51ff61805528a0ccbb7a9c344dfee40d3b9d77f741c649e419c10ddd83ba62be25bca8c3e8cd2dcb3c9c6cc2c0529e8f4ca0f4d27dc84f8
data/.drone.yml ADDED
@@ -0,0 +1,90 @@
1
+ ---
2
+ kind: pipeline
3
+ name: publish
4
+
5
+ clone:
6
+ depth: 1
7
+
8
+ steps:
9
+ - name: restore-bundle-cache
10
+ image: meltwater/drone-cache:latest
11
+ environment:
12
+ AWS_ACCESS_KEY_ID:
13
+ from_secret: CI_AWS_ACCESS_KEY_ID
14
+ AWS_SECRET_ACCESS_KEY:
15
+ from_secret: CI_AWS_SECRET_ACCESS_KEY
16
+ settings:
17
+ restore: true
18
+ cache_key: '{{ checksum "Gemfile.lock" }}'
19
+ bucket: drone-ci-cache-bucket
20
+ region: ap-northeast-1
21
+ mount:
22
+ - 'vendor/bundle'
23
+
24
+ - name: build
25
+ image: ruby:2-alpine
26
+ commands:
27
+ - apk add --no-cache build-base git
28
+ - gem install bundler:2.3.14
29
+ - bundle install -j4
30
+ - rake build
31
+
32
+ - name: rebuild-bundle-cache
33
+ image: meltwater/drone-cache:latest
34
+ environment:
35
+ AWS_ACCESS_KEY_ID:
36
+ from_secret: CI_AWS_ACCESS_KEY_ID
37
+ AWS_SECRET_ACCESS_KEY:
38
+ from_secret: CI_AWS_SECRET_ACCESS_KEY
39
+ settings:
40
+ rebuild: true
41
+ cache_key: '{{ checksum "Gemfile.lock" }}'
42
+ bucket: drone-ci-cache-bucket
43
+ region: ap-northeast-1
44
+ mount:
45
+ - 'vendor/bundle'
46
+ when:
47
+ status:
48
+ - success
49
+ - failure
50
+
51
+ - name: deployment
52
+ image: ruby:alpine
53
+ environment:
54
+ PUSH_KEY:
55
+ from_secret: PUSH_KEY
56
+ commands:
57
+ - mkdir -p ~/.gem
58
+ - touch ~/.gem/credentials
59
+ - echo -e "$PUSH_KEY" > ~/.gem/credentials
60
+ - chmod 0600 ~/.gem/credentials
61
+ - gem push --key push_key pkg/*.gem
62
+
63
+ trigger:
64
+ event:
65
+ - tag
66
+
67
+ ---
68
+ kind: pipeline
69
+ name: after
70
+
71
+ clone:
72
+ disable: true
73
+
74
+ steps:
75
+ - name: notify
76
+ image: plugins/slack
77
+ settings:
78
+ icon_emoji: ":rocket:"
79
+ webhook:
80
+ from_secret: SLACK_WEBHOOK
81
+
82
+ depends_on:
83
+ - publish
84
+
85
+ trigger:
86
+ event:
87
+ - tag
88
+ status:
89
+ - success
90
+ - failure
data/.gitignore ADDED
@@ -0,0 +1,14 @@
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
+
13
+ # rbenv
14
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.4
7
+ before_install: gem install bundler -v 2.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+
3
+ ## v0.2.0 / 2022-09-12
4
+ ### Added
5
+ - Add apps api
6
+
7
+ ## v0.1.0 / 2022-08-21
8
+ ### Added
9
+ - Create project
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kc-sdk-app.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kc-sdk-app (0.2.0)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.5.0)
11
+ docile (1.4.0)
12
+ domain_name (0.5.20190701)
13
+ unf (>= 0.0.5, < 1.0.0)
14
+ http-accept (1.7.0)
15
+ http-cookie (1.0.5)
16
+ domain_name (~> 0.5)
17
+ mime-types (3.4.1)
18
+ mime-types-data (~> 3.2015)
19
+ mime-types-data (3.2022.0105)
20
+ netrc (0.11.0)
21
+ rake (10.5.0)
22
+ rest-client (2.1.0)
23
+ http-accept (>= 1.7.0, < 2.0)
24
+ http-cookie (>= 1.0.2, < 2.0)
25
+ mime-types (>= 1.16, < 4.0)
26
+ netrc (~> 0.8)
27
+ rspec (3.11.0)
28
+ rspec-core (~> 3.11.0)
29
+ rspec-expectations (~> 3.11.0)
30
+ rspec-mocks (~> 3.11.0)
31
+ rspec-core (3.11.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-expectations (3.11.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-its (1.3.0)
37
+ rspec-core (>= 3.0.0)
38
+ rspec-expectations (>= 3.0.0)
39
+ rspec-mocks (3.11.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.11.0)
42
+ rspec-support (3.11.0)
43
+ simplecov (0.21.2)
44
+ docile (~> 1.1)
45
+ simplecov-html (~> 0.11)
46
+ simplecov_json_formatter (~> 0.1)
47
+ simplecov-html (0.12.3)
48
+ simplecov_json_formatter (0.1.4)
49
+ unf (0.1.4)
50
+ unf_ext
51
+ unf_ext (0.0.8.2)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 2.0)
58
+ kc-sdk-app!
59
+ rake (~> 10.0)
60
+ rspec (~> 3.0)
61
+ rspec-its
62
+ simplecov (~> 0.21.2)
63
+
64
+ BUNDLED WITH
65
+ 2.3.14
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ [![Build Status](https://ci.kabob.io/api/badges/kabobcompany/kc-sdk-app-ruby/status.svg)](https://ci.kabob.io/kabobcompany/kc-sdk-app-ruby)
2
+ # kc-sdk-app
3
+ Provides kabob cloud app api client.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kc-sdk-app'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kc-sdk-app
20
+
21
+ For rails, create config `config/initializers/kc_sdk_app.rb`
22
+
23
+ ```ruby
24
+ KcSdkApp.configure do |config|
25
+ # kabob cloud api url, default: https://cloud.kabob.io
26
+ config.api_url = 'https://cloud.kabob.io'
27
+
28
+ # you have to set your app access token
29
+ config.access_token = 'YOUR_APP_ACCESS_TOKEN'
30
+
31
+ # you can set a logger if you want logging api request
32
+ # config.logger = Rails.logger
33
+ end
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ [Api](#api)
39
+
40
+ ### Api
41
+ #### Apps
42
+ ##### current
43
+ Get current app
44
+ ```ruby
45
+ result = KcSdkApp.api.apps.current
46
+ # { "uid": 'kabob.lookr' }
47
+ ```
48
+
49
+
50
+ #### Orders
51
+ ##### surplus
52
+ Get surplus
53
+ ```ruby
54
+ result = KcSdkApp.api.orders.surplus(company_id: 1, plan: 'go', scope: 'point')
55
+ # { "data": 10, is_trial: false }
56
+ ```
57
+
58
+ ```ruby
59
+ result = KcSdkApp.api.orders.surplus(company_id: 1, plan: 'go', scope: 'license')
60
+ # { "data": 10, is_trial: false, active_until: '2030-01-01 00:00:00' }
61
+ ```
62
+
63
+ ##### consuming
64
+ Consume order balance
65
+ ```ruby
66
+ result = KcSdkApp.api.orders.consuming(company_id: 1, plan: 'go', scope: 'point', quantity: 1, taken_at: '2020-12-25 00:00:00 UTC', uid: 'uid')
67
+ # { "meta": { "code": 0 } }
68
+ ```
69
+
70
+ #### Switch App
71
+ The default app access token is the one defined in configuration.
72
+
73
+ If you want to request data as other apps, new an api instance with other access_token.
74
+ ```ruby
75
+ kc_api = KcSdkApp::Api.new(access_token: 'OTHER_APP_ACCESS_TOKEN')
76
+ kc_api.apps.current
77
+ # { "uid": 'kabob.other_app' }
78
+ ```
79
+
80
+ ## Contact
81
+ The project's website is located at https://github.com/kabobcompany/kc-sdk-app-ruby
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 "kabob/cloud/client"
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,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "kc-sdk-app/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kc-sdk-app"
8
+ spec.version = KcSdkApp::VERSION
9
+ spec.authors = ["Yi-Cyuan Chen"]
10
+ spec.email = ["emn178@gmail.com"]
11
+
12
+ spec.summary = %q{Kabob cloud client library.}
13
+ spec.description = %q{Kabob cloud client library.}
14
+ spec.homepage = "https://github.com/kabobcompany/kc-sdk-app-ruby"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/kabobcompany/kc-sdk-app-ruby"
23
+ spec.metadata["changelog_uri"] = "https://github.com/kabobcompany/kc-sdk-app-ruby/CHANGELOG.md"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|tmp)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency "rest-client"
39
+ spec.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_development_dependency "rspec-its"
43
+ spec.add_development_dependency "simplecov", "~> 0.21.2"
44
+ end
@@ -0,0 +1,10 @@
1
+ module KcSdkApp
2
+ class Api
3
+ class Apps < Base
4
+ def current
5
+ resp = resource['v1/apps/current'].get
6
+ JSON.parse(resp.body)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module KcSdkApp
2
+ class Api
3
+ class Base
4
+ def initialize(api)
5
+ @api = api
6
+ end
7
+
8
+ def resource
9
+ @api.resource
10
+ end
11
+
12
+ def validate_keys!(hash, keys)
13
+ keys.each do |k|
14
+ raise ArgumentError, "required keywords: #{keys.join(', ')}" unless hash.key?(k)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module KcSdkApp
2
+ class Api
3
+ class Orders < Base
4
+ def surplus(query)
5
+ validate_keys!(query, %i[company_id plan scope])
6
+ resp = resource['v1/orders/surplus'].get({ params: query })
7
+ JSON.parse(resp.body)
8
+ end
9
+
10
+ def consuming(data)
11
+ validate_keys!(data, %i[company_id plan scope quantity taken_at uid])
12
+ resp = resource['v1/orders/consuming'].post(data)
13
+ JSON.parse(resp.body)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'kc-sdk-app/api/base'
2
+ require 'kc-sdk-app/api/orders'
3
+ require 'kc-sdk-app/api/apps'
4
+
5
+ module KcSdkApp
6
+ class Api
7
+ attr_accessor :access_token
8
+ attr_accessor :orders
9
+ attr_accessor :apps
10
+
11
+ def initialize(access_token: KcSdkApp.configuration.access_token)
12
+ self.access_token = access_token
13
+ self.orders = KcSdkApp::Api::Orders.new(self)
14
+ self.apps = KcSdkApp::Api::Apps.new(self)
15
+ end
16
+
17
+ def resource
18
+ @resource ||= RestClient::Resource.new(
19
+ "#{KcSdkApp.configuration.api_url}/api/app",
20
+ log: KcSdkApp.configuration.logger,
21
+ headers: { 'Authorization': "Bearer #{self.access_token}" }
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ module KcSdkApp
2
+ class Configuration
3
+ attr_accessor :api_url, :access_token, :logger
4
+
5
+ def initialize(options = {})
6
+ options.each do |key, value|
7
+ instance_variable_set("@#{key}", value)
8
+ end
9
+ @api_url ||= 'https://cloud.kabob.io'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module KcSdkApp
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module KcSdkApp
2
+ VERSION = '0.2.0'.freeze
3
+ end
data/lib/kc-sdk-app.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'rest-client'
2
+ require 'kc-sdk-app/version'
3
+ require 'kc-sdk-app/configuration'
4
+ require 'kc-sdk-app/api'
5
+
6
+ require 'kc-sdk-app/engine' if defined?(::Rails)
7
+
8
+ module KcSdkApp
9
+ def self.configure
10
+ yield configuration
11
+ end
12
+
13
+ def self.configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def self.api
18
+ @api ||= Api.new
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kc-sdk-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Yi-Cyuan Chen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.21.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.21.2
97
+ description: Kabob cloud client library.
98
+ email:
99
+ - emn178@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".drone.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - kc-sdk-app.gemspec
116
+ - lib/kc-sdk-app.rb
117
+ - lib/kc-sdk-app/api.rb
118
+ - lib/kc-sdk-app/api/apps.rb
119
+ - lib/kc-sdk-app/api/base.rb
120
+ - lib/kc-sdk-app/api/orders.rb
121
+ - lib/kc-sdk-app/configuration.rb
122
+ - lib/kc-sdk-app/engine.rb
123
+ - lib/kc-sdk-app/version.rb
124
+ homepage: https://github.com/kabobcompany/kc-sdk-app-ruby
125
+ licenses: []
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org/
128
+ homepage_uri: https://github.com/kabobcompany/kc-sdk-app-ruby
129
+ source_code_uri: https://github.com/kabobcompany/kc-sdk-app-ruby
130
+ changelog_uri: https://github.com/kabobcompany/kc-sdk-app-ruby/CHANGELOG.md
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.1.6
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Kabob cloud client library.
150
+ test_files: []