tea_core 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +8 -0
- data/lib/tea_core.rb +108 -0
- data/spec/spec_helper.rb +110 -0
- data/spec/tea_spec.rb +118 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 41582ad7a312554083300a83f5e387ed3c70c9141e042a85e81e172d7e27e7e0
|
4
|
+
data.tar.gz: 50c5f4dabaf7e7e1a5445ebf0b8d9291b5f290bd3346a83fa479a8b8e9da8b0a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f8a334a2274e574ae11a6f877085a7e45f72fc6da90236f6c5cbec6ab0e6b13e1f2a9649a4b32d2d5fa9e62a5b6449d6f5b32ff118b5bc3753851824742fdf7
|
7
|
+
data.tar.gz: cdae6e0f45d8b6f4c56c7d92da300d6951b7a8ff35e1da96bf054c04e60f659ea50e0e37382fb850d2c98341f95850ca6c218c969af4ddd3f21f3fd8f25e9089
|
data/README.md
ADDED
data/lib/tea_core.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
# The Tea module
|
6
|
+
module Tea
|
7
|
+
VERSION = '0.0.1'
|
8
|
+
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def allow_retry(_retry_policy, retry_times, _now)
|
12
|
+
# TODO
|
13
|
+
return false if retry_times > 2
|
14
|
+
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
# The Model class
|
19
|
+
class Model
|
20
|
+
def to_hash
|
21
|
+
hash = {}
|
22
|
+
names = self.class.name_mapping
|
23
|
+
names.each do |key, value|
|
24
|
+
hash[value] = instance_variable_get('@' + key)
|
25
|
+
end
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
|
29
|
+
# new Model from hash
|
30
|
+
def initialize(hash = nil)
|
31
|
+
return if hash.nil?
|
32
|
+
|
33
|
+
names = self.class.name_mapping
|
34
|
+
types = self.class.type_mapping
|
35
|
+
|
36
|
+
names.each do |key, value|
|
37
|
+
type = types[key]
|
38
|
+
if type.instance_of? Hash
|
39
|
+
# array
|
40
|
+
if type['type'].instance_of? String
|
41
|
+
if type['type'] == 'array'
|
42
|
+
instance_variable_set('@' + key, hash[value].map do |item|
|
43
|
+
type['itemType'].new(item)
|
44
|
+
end)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
instance_variable_set('@' + key, type.new(hash[value]))
|
48
|
+
end
|
49
|
+
elsif type.instance_of? Class
|
50
|
+
instance_variable_set('@' + key, type.new(hash[value]))
|
51
|
+
else
|
52
|
+
instance_variable_set('@' + key, hash[value])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# The RetryError class
|
59
|
+
class RetryError < StandardError
|
60
|
+
def initialize(request, response); end
|
61
|
+
end
|
62
|
+
|
63
|
+
def retryable?(err)
|
64
|
+
err.instance_of?(RetryError)
|
65
|
+
end
|
66
|
+
|
67
|
+
def unable_retry_error(request)
|
68
|
+
# TODO
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_backoff_time(_policy, _times)
|
72
|
+
0
|
73
|
+
end
|
74
|
+
|
75
|
+
# The UnableRetryError class
|
76
|
+
class UnableRetryError < StandardError
|
77
|
+
def initialize(request); end
|
78
|
+
end
|
79
|
+
|
80
|
+
# The Error class
|
81
|
+
class Error < StandardError
|
82
|
+
def initialize(err)
|
83
|
+
super(err['message'])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_uri(req)
|
88
|
+
type = req['protocol'] == 'https' ? URI::HTTPS : URI::HTTP
|
89
|
+
uri = type.build(
|
90
|
+
host: req['headers']['host'],
|
91
|
+
path: req['pathname'],
|
92
|
+
query: URI.encode_www_form(req['query']),
|
93
|
+
fragment: ''
|
94
|
+
)
|
95
|
+
uri.port = req['port'] if req['port']
|
96
|
+
uri
|
97
|
+
end
|
98
|
+
|
99
|
+
def do_request(request)
|
100
|
+
uri = to_uri(request)
|
101
|
+
case request['method'].downcase || 'get'
|
102
|
+
when 'get'
|
103
|
+
return Net::HTTP.get_response(uri)
|
104
|
+
else
|
105
|
+
puts 'default'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter '/spec/'
|
6
|
+
end
|
7
|
+
|
8
|
+
if ENV['CI'] == 'true'
|
9
|
+
require 'codecov'
|
10
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
11
|
+
end
|
12
|
+
|
13
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
14
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
15
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
16
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
17
|
+
# files.
|
18
|
+
#
|
19
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
20
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
21
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
22
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
23
|
+
# a separate helper file that requires the additional dependencies and performs
|
24
|
+
# the additional setup, and require it from the spec files that actually need
|
25
|
+
# it.
|
26
|
+
#
|
27
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
28
|
+
RSpec.configure do |config|
|
29
|
+
# rspec-expectations config goes here. You can use an alternate
|
30
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
31
|
+
# assertions if you prefer.
|
32
|
+
config.expect_with :rspec do |expectations|
|
33
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
34
|
+
# and `failure_message` of custom matchers include text for helper methods
|
35
|
+
# defined using `chain`, e.g.:
|
36
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
37
|
+
# # => "be bigger than 2 and smaller than 4"
|
38
|
+
# ...rather than:
|
39
|
+
# # => "be bigger than 2"
|
40
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
44
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
45
|
+
config.mock_with :rspec do |mocks|
|
46
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
47
|
+
# a real object. This is generally recommended, and will default to
|
48
|
+
# `true` in RSpec 4.
|
49
|
+
mocks.verify_partial_doubles = true
|
50
|
+
end
|
51
|
+
|
52
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
53
|
+
# have no way to turn it off -- the option exists only for backwards
|
54
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
55
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
56
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
57
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
58
|
+
|
59
|
+
# The settings below are suggested to provide a good initial experience
|
60
|
+
# with RSpec, but feel free to customize to your heart's content.
|
61
|
+
# # This allows you to limit a spec run to individual examples or groups
|
62
|
+
# # you care about by tagging them with `:focus` metadata. When nothing
|
63
|
+
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
64
|
+
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
65
|
+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
66
|
+
# config.filter_run_when_matching :focus
|
67
|
+
#
|
68
|
+
# # Allows RSpec to persist some state between runs in order to support
|
69
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
70
|
+
# # you configure your source control system to ignore this file.
|
71
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
72
|
+
#
|
73
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
74
|
+
# # recommended. For more details, see:
|
75
|
+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
76
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
77
|
+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
78
|
+
# config.disable_monkey_patching!
|
79
|
+
#
|
80
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
81
|
+
# # be too noisy due to issues in dependencies.
|
82
|
+
# config.warnings = true
|
83
|
+
#
|
84
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
85
|
+
# # file, and it's useful to allow more verbose output when running an
|
86
|
+
# # individual spec file.
|
87
|
+
# if config.files_to_run.one?
|
88
|
+
# # Use the documentation formatter for detailed output,
|
89
|
+
# # unless a formatter has already been configured
|
90
|
+
# # (e.g. via a command-line flag).
|
91
|
+
# config.default_formatter = "doc"
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# # Print the 10 slowest examples and example groups at the
|
95
|
+
# # end of the spec run, to help surface which specs are running
|
96
|
+
# # particularly slow.
|
97
|
+
# config.profile_examples = 10
|
98
|
+
#
|
99
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
100
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
101
|
+
# # the seed, which is printed after each run.
|
102
|
+
# # --seed 1234
|
103
|
+
# config.order = :random
|
104
|
+
#
|
105
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
106
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
107
|
+
# # test failures related to randomization by passing the same `--seed` value
|
108
|
+
# # as the one that triggered the failure.
|
109
|
+
# Kernel.srand config.seed
|
110
|
+
end
|
data/spec/tea_spec.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
require 'tea_core'
|
6
|
+
|
7
|
+
describe 'Tea' do
|
8
|
+
class MyModel < Tea::Model
|
9
|
+
attr_accessor :request_id, :page_number, :page_size, :total_count
|
10
|
+
def self.name_mapping
|
11
|
+
{
|
12
|
+
'request_id' => 'RequestId',
|
13
|
+
'page_number' => 'PageNumber',
|
14
|
+
'page_size' => 'PageSize',
|
15
|
+
'total_count' => 'TotalCount'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.type_mapping
|
20
|
+
{
|
21
|
+
'request_id' => 'string',
|
22
|
+
'page_number' => 'string',
|
23
|
+
'page_size' => 'string',
|
24
|
+
'total_count' => 'string'
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'model should ok' do
|
30
|
+
model = MyModel.new(
|
31
|
+
'RequestId' => 'request id'
|
32
|
+
)
|
33
|
+
expect(model.request_id).to eq('request id')
|
34
|
+
hash = model.to_hash
|
35
|
+
expect(hash).to eql(
|
36
|
+
'RequestId' => 'request id',
|
37
|
+
'PageNumber' => nil,
|
38
|
+
'PageSize' => nil,
|
39
|
+
'TotalCount' => nil
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
class DescribeRegionsResponse < Tea::Model
|
44
|
+
attr_accessor :request_id, :regions
|
45
|
+
def self.name_mapping
|
46
|
+
{
|
47
|
+
'request_id' => 'RequestId',
|
48
|
+
'regions' => 'Regions'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.type_mapping
|
53
|
+
{
|
54
|
+
'request_id' => 'string',
|
55
|
+
'regions' => DescribeRegionsResponseRegions
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class DescribeRegionsResponseRegionsRegion < Tea::Model
|
61
|
+
attr_accessor :region_id, :local_name, :region_endpoint, :status
|
62
|
+
def self.name_mapping
|
63
|
+
{
|
64
|
+
'region_id' => 'RegionId',
|
65
|
+
'local_name' => 'LocalName',
|
66
|
+
'region_endpoint' => 'RegionEndpoint',
|
67
|
+
'status' => 'Status'
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.type_mapping
|
72
|
+
{
|
73
|
+
'region_id' => 'string',
|
74
|
+
'local_name' => 'string',
|
75
|
+
'region_endpoint' => 'string',
|
76
|
+
'status' => 'string'
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class DescribeRegionsResponseRegions < Tea::Model
|
82
|
+
attr_accessor :region
|
83
|
+
def self.name_mapping
|
84
|
+
{
|
85
|
+
'region' => 'Region'
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.type_mapping
|
90
|
+
{
|
91
|
+
'region' => { 'type' => 'array', 'itemType' => DescribeRegionsResponseRegionsRegion }
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'submodel should ok' do
|
97
|
+
model = DescribeRegionsResponse.new(
|
98
|
+
'RequestId' => '4CB944B5-94EC-42D1-82DE-80D206FA237D',
|
99
|
+
'Regions' => {
|
100
|
+
'Region' => [
|
101
|
+
{
|
102
|
+
'RegionId' => 'cn-qingdao',
|
103
|
+
'RegionEndpoint' => 'ecs.aliyuncs.com',
|
104
|
+
'LocalName' => '华北 1'
|
105
|
+
}
|
106
|
+
]
|
107
|
+
}
|
108
|
+
)
|
109
|
+
|
110
|
+
expect(model.regions.region).to be_an_instance_of(Array)
|
111
|
+
expect(model.regions.region.length).to eq(1)
|
112
|
+
region = model.regions.region[0]
|
113
|
+
expect(region).to be_an_instance_of(DescribeRegionsResponseRegionsRegion)
|
114
|
+
expect(region.region_id).to eq('cn-qingdao')
|
115
|
+
expect(region.region_endpoint).to eq('ecs.aliyuncs.com')
|
116
|
+
expect(region.local_name).to eq('华北 1')
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tea_core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alibaba Cloud SDK
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: codecov
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.10
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.10
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.8.0
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '3.8'
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.8.0
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '3.8'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: simplecov
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.16'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.16.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.16'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.16.1
|
73
|
+
description: Tea Core SDK for Ruby
|
74
|
+
email:
|
75
|
+
- sdk-team@alibabacloud.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- README.md
|
81
|
+
- lib/tea_core.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
- spec/tea_spec.rb
|
84
|
+
homepage: http://www.alibabacloud.com/
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubygems_version: 3.0.4
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Tea Core SDK for Ruby
|
107
|
+
test_files:
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/tea_spec.rb
|