lvmama-api 0.1.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 +7 -0
- data/.gitignore +2 -0
- data/README.md +32 -0
- data/Rakefile +3 -0
- data/lib/lvmama-api.rb +26 -0
- data/lib/lvmama-api/api.rb +29 -0
- data/lib/lvmama-api/client.rb +9 -0
- data/lib/lvmama-api/client/ticket_prod.rb +47 -0
- data/lib/lvmama-api/configuration.rb +86 -0
- data/lib/lvmama-api/connection.rb +27 -0
- data/lib/lvmama-api/error.rb +31 -0
- data/lib/lvmama-api/request.rb +60 -0
- data/lib/lvmama-api/version.rb +3 -0
- data/lvmama-api.gemspec +21 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a8f92ae21ea4f0b15cd4f7ac2cb8b936e001fba
|
4
|
+
data.tar.gz: 6ce22a3ed7daf4b87584e317fa6e97dd537f7be0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68fba6090fc71f3d0d968af8a905ca87675a6adaf7c769c047497cb494f821e930f6144c366fcbd7ec5a4bf86a57058b2006257f73cc0b25e810df20ad1e8485
|
7
|
+
data.tar.gz: 55a8bab8f9f902576bdf6313a7785e4df4b4daff8ce8b7919771e3404c23062c7676c08ae4e8dd5df43be0b967b1d81db1996536bcb1f35ef471f1e544efb4f2
|
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
The Lvmama API Ruby Gem
|
2
|
+
====================
|
3
|
+
A simple Ruby wrapper for the Lvmama APIs.
|
4
|
+
|
5
|
+
It's not a official Ruby Gem.
|
6
|
+
If you want to get the origin document, please contact: [http://www.lvmama.com/](http://www.lvmama.com/).
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
gem install lvmama-api
|
11
|
+
|
12
|
+
|
13
|
+
Configuration
|
14
|
+
-------------
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
Lvmama.configure do |config|
|
18
|
+
config.client_id = 'appKey'
|
19
|
+
config.client_secret = 'secret'
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Get the scenic list
|
28
|
+
response = Lvmama.scenic_info_list_by_page 1
|
29
|
+
|
30
|
+
# Use the response
|
31
|
+
response[:scenicNameList][0][:scenicId]
|
32
|
+
```
|
data/Rakefile
ADDED
data/lib/lvmama-api.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../lvmama-api/error', __FILE__)
|
2
|
+
require File.expand_path('../lvmama-api/configuration', __FILE__)
|
3
|
+
require File.expand_path('../lvmama-api/api', __FILE__)
|
4
|
+
require File.expand_path('../lvmama-api/client', __FILE__)
|
5
|
+
|
6
|
+
module Lvmama
|
7
|
+
extend Configuration
|
8
|
+
|
9
|
+
# Alias for Lvmama::Client.new
|
10
|
+
#
|
11
|
+
# @return [Lvmama::Client]
|
12
|
+
def self.client(options={})
|
13
|
+
Lvmama::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to Lvmama::Client
|
17
|
+
def self.method_missing(method, *args, &block)
|
18
|
+
return super unless client.respond_to?(method)
|
19
|
+
client.send(method, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Delegate to Lvmama::Client
|
23
|
+
def self.respond_to?(method, include_all=false)
|
24
|
+
return client.respond_to?(method, include_all) || super
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../connection', __FILE__)
|
2
|
+
require File.expand_path('../request', __FILE__)
|
3
|
+
|
4
|
+
module Lvmama
|
5
|
+
# @private
|
6
|
+
class API
|
7
|
+
# @private
|
8
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
9
|
+
|
10
|
+
# Creates a new API
|
11
|
+
def initialize(options={})
|
12
|
+
options = Lvmama.options.merge(options)
|
13
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
|
+
send("#{key}=", options[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
conf = {}
|
20
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
21
|
+
conf[key] = send key
|
22
|
+
end
|
23
|
+
conf
|
24
|
+
end
|
25
|
+
|
26
|
+
include Connection
|
27
|
+
include Request
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lvmama
|
2
|
+
class Client
|
3
|
+
module TicketProd
|
4
|
+
ENDPOINT = "distributorApi/2.0/api/ticketProd/".freeze
|
5
|
+
|
6
|
+
def scenic_info_list_by_page current_page, options={}
|
7
|
+
options[:currentPage] = current_page
|
8
|
+
response = post ENDPOINT + "scenicInfoListByPage", options
|
9
|
+
response
|
10
|
+
end
|
11
|
+
|
12
|
+
def product_info_list_by_page current_page, options={}
|
13
|
+
options[:currentPage] = current_page
|
14
|
+
response = post ENDPOINT + "productInfoListByPage", options
|
15
|
+
response
|
16
|
+
end
|
17
|
+
|
18
|
+
def product_price_list_by_page current_page, begin_date, end_date, options={}
|
19
|
+
options[:currentPage] = current_page
|
20
|
+
options[:beginDate] = begin_date
|
21
|
+
options[:endDate] = end_date
|
22
|
+
response = post ENDPOINT + "productPriceListByPage", options
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
def product_info_list product_ids, options={}
|
27
|
+
options[:productIds] = product_ids
|
28
|
+
response = post ENDPOINT + "productInfoList", options
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
def good_info_list goods_ids, options={}
|
33
|
+
options[:goodsIds] = goods_ids
|
34
|
+
response = post ENDPOINT + "goodInfoList", options
|
35
|
+
response
|
36
|
+
end
|
37
|
+
|
38
|
+
def good_price_list goods_ids, begin_date, end_date, options={}
|
39
|
+
options[:goodsIds] = goods_ids
|
40
|
+
options[:beginDate] = begin_date
|
41
|
+
options[:endDate] = end_date
|
42
|
+
response = post ENDPOINT + "goodPriceList", options
|
43
|
+
response
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
3
|
+
|
4
|
+
module Lvmama
|
5
|
+
# Defines constants and methods related to configuration
|
6
|
+
module Configuration
|
7
|
+
# An array of valid keys in the options hash when configuring a {Lvmama::API}
|
8
|
+
VALID_OPTIONS_KEYS = [
|
9
|
+
:adapter,
|
10
|
+
:client_id,
|
11
|
+
:client_secret,
|
12
|
+
:connection_options,
|
13
|
+
:endpoint,
|
14
|
+
:format,
|
15
|
+
:user_agent,
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
|
19
|
+
# The adapter that will be used to connect if none is set
|
20
|
+
#
|
21
|
+
# @note The default faraday adapter is Net::HTTP.
|
22
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
23
|
+
|
24
|
+
# By default, don't set an application ID
|
25
|
+
DEFAULT_CLIENT_ID = nil
|
26
|
+
|
27
|
+
# By default, don't set an application secret
|
28
|
+
DEFAULT_CLIENT_SECRET = nil
|
29
|
+
|
30
|
+
# By default, don't set any connection options
|
31
|
+
DEFAULT_CONNECTION_OPTIONS = {}
|
32
|
+
|
33
|
+
# The endpoint that will be used to connect if none is set
|
34
|
+
#
|
35
|
+
# @note There is no reason to use any other endpoint at this time
|
36
|
+
DEFAULT_ENDPOINT = 'http://api.lvmama.com'.freeze
|
37
|
+
# Develop endpoint
|
38
|
+
#DEFAULT_ENDPOINT = 'http://180.169.51.94/api1/'.freeze
|
39
|
+
|
40
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
41
|
+
#
|
42
|
+
# @note JSON is the only available format at this time
|
43
|
+
DEFAULT_FORMAT = :json
|
44
|
+
|
45
|
+
|
46
|
+
# The user agent that will be sent to the API endpoint if none is set
|
47
|
+
DEFAULT_USER_AGENT = "Lvmama Ruby Gem #{Lvmama::VERSION}".freeze
|
48
|
+
|
49
|
+
# An array of valid request/response formats
|
50
|
+
#
|
51
|
+
# @note Not all methods support the XML format.
|
52
|
+
VALID_FORMATS = [
|
53
|
+
:json].freeze
|
54
|
+
|
55
|
+
# @private
|
56
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
57
|
+
|
58
|
+
# When this module is extended, set all configuration options to their default values
|
59
|
+
def self.extended(base)
|
60
|
+
base.reset
|
61
|
+
end
|
62
|
+
|
63
|
+
# Convenience method to allow configuration options to be set in a block
|
64
|
+
def configure
|
65
|
+
yield self
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create a hash of options and their values
|
69
|
+
def options
|
70
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
71
|
+
option.merge!(key => send(key))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Reset all configuration options to defaults
|
76
|
+
def reset
|
77
|
+
self.adapter = DEFAULT_ADAPTER
|
78
|
+
self.client_id = DEFAULT_CLIENT_ID
|
79
|
+
self.client_secret = DEFAULT_CLIENT_SECRET
|
80
|
+
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
81
|
+
self.endpoint = DEFAULT_ENDPOINT
|
82
|
+
self.format = DEFAULT_FORMAT
|
83
|
+
self.user_agent = DEFAULT_USER_AGENT
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module Lvmama
|
4
|
+
# @private
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
|
8
|
+
def connection(raw=false)
|
9
|
+
options = {
|
10
|
+
:headers => {'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
|
11
|
+
:url => endpoint,
|
12
|
+
}.merge(connection_options)
|
13
|
+
|
14
|
+
Faraday::Connection.new(options) do |connection|
|
15
|
+
connection.use Faraday::Request::UrlEncoded
|
16
|
+
connection.use FaradayMiddleware::Mashify unless raw
|
17
|
+
unless raw
|
18
|
+
case format.to_s.downcase
|
19
|
+
when 'json' then connection.use Faraday::Response::ParseJson
|
20
|
+
end
|
21
|
+
end
|
22
|
+
#connection.use FaradayMiddleware::RaiseHttpException
|
23
|
+
connection.adapter(adapter)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Lvmama
|
2
|
+
# Custom error class for rescuing from all Lvmama errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Lvmama returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Lvmama returns the HTTP status code 404
|
9
|
+
class NotFound < Error; end
|
10
|
+
|
11
|
+
# Raised when Lvmama returns the HTTP status code 429
|
12
|
+
class TooManyRequests < Error; end
|
13
|
+
|
14
|
+
# Raised when Lvmama returns the HTTP status code 500
|
15
|
+
class InternalServerError < Error; end
|
16
|
+
|
17
|
+
# Raised when Lvmama returns the HTTP status code 502
|
18
|
+
class BadGateway < Error; end
|
19
|
+
|
20
|
+
# Raised when Lvmama returns the HTTP status code 503
|
21
|
+
class ServiceUnavailable < Error; end
|
22
|
+
|
23
|
+
# Raised when Lvmama returns the HTTP status code 504
|
24
|
+
class GatewayTimeout < Error; end
|
25
|
+
|
26
|
+
# Raised when a subscription payload hash is invalid
|
27
|
+
class InvalidSignature < Error; end
|
28
|
+
|
29
|
+
# Raised when Lvmama returns the HTTP status code 429
|
30
|
+
class RateLimitExceeded < Error; end
|
31
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module Lvmama
|
4
|
+
# Defines HTTP request methods
|
5
|
+
module Request
|
6
|
+
# Perform an HTTP GET request
|
7
|
+
def get(path, options={}, raw=false)
|
8
|
+
request(:get, path, options, raw)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Perform an HTTP POST request
|
12
|
+
def post(path, options={}, raw=false)
|
13
|
+
request(:get, path, options, raw)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Perform an HTTP PUT request
|
17
|
+
def put(path, options={}, raw=false)
|
18
|
+
request(:get, path, options, raw)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Perform an HTTP DELETE request
|
22
|
+
def delete(path, options={}, raw=false)
|
23
|
+
request(:get, path, options, raw)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Perform an HTTP request
|
29
|
+
def request(method, path, options, raw=false)
|
30
|
+
response = connection(raw).send(method) do |request|
|
31
|
+
timestamp = Time.now.getutc.to_i
|
32
|
+
sign = generate_sign timestamp.to_s, client_secret
|
33
|
+
|
34
|
+
options[:appKey] = client_id
|
35
|
+
options[:messageFormat] = format
|
36
|
+
options[:timestamp] = timestamp
|
37
|
+
options[:sign] = sign
|
38
|
+
|
39
|
+
case method
|
40
|
+
when :get, :delete
|
41
|
+
request.url(URI.encode(path), options)
|
42
|
+
when :post, :put
|
43
|
+
request.path = URI.encode(path)
|
44
|
+
request.body = options unless options.empty?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
raw ? response : response.body
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_sign timestamp, secret
|
52
|
+
sign = secret + timestamp + secret
|
53
|
+
md5 = Digest::MD5.new
|
54
|
+
md5 << sign
|
55
|
+
md5.hexdigest
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/lvmama-api.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../lib/lvmama-api/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Samwise Wang"]
|
5
|
+
gem.email = ["wangjunzhe4444@gmail.com"]
|
6
|
+
gem.description = %q{A Ruby wrapper for the Lvmama API}
|
7
|
+
gem.summary = %q{Ruby wrapper for the Lvmama API}
|
8
|
+
gem.homepage = "https://github.com/tzwm/lvmama-api-ruby"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "lvmama-api"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Lvmama::VERSION.dup
|
16
|
+
gem.license = 'MIT'
|
17
|
+
|
18
|
+
gem.add_dependency 'faraday', '~> 0.9.1'
|
19
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9.1'
|
20
|
+
end
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lvmama-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samwise Wang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.1
|
41
|
+
description: A Ruby wrapper for the Lvmama API
|
42
|
+
email:
|
43
|
+
- wangjunzhe4444@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/lvmama-api.rb
|
52
|
+
- lib/lvmama-api/api.rb
|
53
|
+
- lib/lvmama-api/client.rb
|
54
|
+
- lib/lvmama-api/client/ticket_prod.rb
|
55
|
+
- lib/lvmama-api/configuration.rb
|
56
|
+
- lib/lvmama-api/connection.rb
|
57
|
+
- lib/lvmama-api/error.rb
|
58
|
+
- lib/lvmama-api/request.rb
|
59
|
+
- lib/lvmama-api/version.rb
|
60
|
+
- lvmama-api.gemspec
|
61
|
+
homepage: https://github.com/tzwm/lvmama-api-ruby
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.4.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Ruby wrapper for the Lvmama API
|
85
|
+
test_files: []
|