qingcloud-sdk 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +674 -0
- data/README.md +96 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/qingcloud/sdk/client/connector.rb +89 -0
- data/lib/qingcloud/sdk/client/foundation.rb +73 -0
- data/lib/qingcloud/sdk/client/service.rb +699 -0
- data/lib/qingcloud/sdk/general/contract.rb +19 -0
- data/lib/qingcloud/sdk/general/error.rb +42 -0
- data/lib/qingcloud/sdk/template/qingcloud.json +4 -0
- data/lib/qingcloud/sdk/utility/file_manager.rb +43 -0
- data/lib/qingcloud/sdk/utility/json_parser.rb +41 -0
- data/lib/qingcloud/sdk/utility/logger.rb +19 -0
- data/lib/qingcloud/sdk/version.rb +7 -0
- data/lib/qingcloud/sdk.rb +15 -0
- data/qingcloud-sdk.gemspec +29 -0
- metadata +109 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
module QingCloud
|
2
|
+
module SDK
|
3
|
+
module Error
|
4
|
+
|
5
|
+
class SDKError < StandardError
|
6
|
+
def initialize(message=nil)
|
7
|
+
super "Encounter Error: #{message || 'Unknown'}."
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class NetworkError < SDKError
|
12
|
+
def message
|
13
|
+
'Network Error, please check your internet connection.'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ServerError < SDKError
|
18
|
+
def initialize(code)
|
19
|
+
super "Server Response with Error Code \"#{code}\"."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ParameterError < SDKError
|
24
|
+
def initialize(something)
|
25
|
+
super "Parameter Error when \"#{something}\"."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class APIError < SDKError
|
30
|
+
def initialize(something)
|
31
|
+
super "API Error: \"#{something}\"."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class AnalyseError < SDKError
|
36
|
+
def initialize(something)
|
37
|
+
super "Analyse Error when \"#{something}\"."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
module QingCloud
|
5
|
+
module SDK
|
6
|
+
module Utility
|
7
|
+
|
8
|
+
def self.file_manager
|
9
|
+
unless self.class_variable_defined? '@@file_manager'
|
10
|
+
FileUtils.mkdir_p Contract::SUPPORT_DIRECTORY
|
11
|
+
@@file_manager = FileManager.new
|
12
|
+
end
|
13
|
+
@@file_manager
|
14
|
+
end
|
15
|
+
|
16
|
+
class FileManager
|
17
|
+
|
18
|
+
def read_config_file
|
19
|
+
read_file Contract::CONFIG_FILE_PATH
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_config_file(content)
|
23
|
+
write_file Contract::CONFIG_FILE_PATH, content
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_new_config_file
|
27
|
+
new_config_file = read_file Contract::TEMPLATE_CONFIG_FILE_PATH
|
28
|
+
write_file Contract::CONFIG_FILE_PATH, new_config_file
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def read_file(file_path)
|
34
|
+
File.open(file_path) { |file| return file.read } if File.exist? file_path
|
35
|
+
end
|
36
|
+
|
37
|
+
def write_file(file_path, content)
|
38
|
+
File.open(file_path, 'w') { |file| file.write content }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module QingCloud
|
4
|
+
module SDK
|
5
|
+
module Utility
|
6
|
+
|
7
|
+
def self.json_parser
|
8
|
+
unless self.class_variable_defined? '@@json_parser'
|
9
|
+
@@json_parser = JsonParser.new
|
10
|
+
end
|
11
|
+
@@json_parser
|
12
|
+
end
|
13
|
+
|
14
|
+
class JsonParser
|
15
|
+
|
16
|
+
def encode(object)
|
17
|
+
guarantee(Proc.new do; JSON.generate object; end)
|
18
|
+
end
|
19
|
+
|
20
|
+
def encode_prettily(object)
|
21
|
+
guarantee(Proc.new do; JSON.pretty_generate object; end)
|
22
|
+
end
|
23
|
+
|
24
|
+
def decode(string)
|
25
|
+
guarantee(Proc.new do; JSON.parse string; end)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def guarantee(proc)
|
31
|
+
begin
|
32
|
+
proc.call
|
33
|
+
rescue JSON::ParserError
|
34
|
+
raise Error::AnalyseError, 'Parse Json'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module QingCloud
|
5
|
+
module SDK
|
6
|
+
module Utility
|
7
|
+
|
8
|
+
def self.logger
|
9
|
+
unless self.class_variable_defined? '@@logger'
|
10
|
+
# @@logger = Logger.new(STDOUT)
|
11
|
+
FileUtils.mkdir_p Contract::SUPPORT_DIRECTORY
|
12
|
+
@@logger = Logger.new Contract::LOG_FILE_PATH
|
13
|
+
end
|
14
|
+
@@logger
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'qingcloud/sdk/version'
|
2
|
+
|
3
|
+
# General
|
4
|
+
require 'qingcloud/sdk/general/contract'
|
5
|
+
require 'qingcloud/sdk/general/error'
|
6
|
+
|
7
|
+
# Utility
|
8
|
+
require 'qingcloud/sdk/utility/logger'
|
9
|
+
require 'qingcloud/sdk/utility/file_manager'
|
10
|
+
require 'qingcloud/sdk/utility/json_parser'
|
11
|
+
|
12
|
+
# Client
|
13
|
+
require 'qingcloud/sdk/client/connector'
|
14
|
+
require 'qingcloud/sdk/client/foundation'
|
15
|
+
require 'qingcloud/sdk/client/service'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qingcloud/sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'qingcloud-sdk'
|
8
|
+
spec.version = QingCloud::SDK::VERSION
|
9
|
+
spec.authors = ['Peng Jingwen']
|
10
|
+
spec.email = ['pengsrc@icloud.com']
|
11
|
+
|
12
|
+
if spec.respond_to?(:metadata)
|
13
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
14
|
+
end
|
15
|
+
|
16
|
+
spec.summary = 'SDK for QingCloud'
|
17
|
+
spec.description = 'SDK for QingCloud'
|
18
|
+
spec.homepage = 'https://github.com/prettyxw/qingcloud-sdk-ruby'
|
19
|
+
spec.license = 'GPL'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qingcloud-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peng Jingwen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-05 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.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
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.2.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.2.0
|
55
|
+
description: SDK for QingCloud
|
56
|
+
email:
|
57
|
+
- pengsrc@icloud.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/qingcloud/sdk.rb
|
72
|
+
- lib/qingcloud/sdk/client/connector.rb
|
73
|
+
- lib/qingcloud/sdk/client/foundation.rb
|
74
|
+
- lib/qingcloud/sdk/client/service.rb
|
75
|
+
- lib/qingcloud/sdk/general/contract.rb
|
76
|
+
- lib/qingcloud/sdk/general/error.rb
|
77
|
+
- lib/qingcloud/sdk/template/qingcloud.json
|
78
|
+
- lib/qingcloud/sdk/utility/file_manager.rb
|
79
|
+
- lib/qingcloud/sdk/utility/json_parser.rb
|
80
|
+
- lib/qingcloud/sdk/utility/logger.rb
|
81
|
+
- lib/qingcloud/sdk/version.rb
|
82
|
+
- qingcloud-sdk.gemspec
|
83
|
+
homepage: https://github.com/prettyxw/qingcloud-sdk-ruby
|
84
|
+
licenses:
|
85
|
+
- GPL
|
86
|
+
metadata:
|
87
|
+
allowed_push_host: https://rubygems.org
|
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
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: SDK for QingCloud
|
108
|
+
test_files: []
|
109
|
+
has_rdoc:
|