superlanding 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 128be102c0646958fc1da44d47940f04ce3197af
4
+ data.tar.gz: dee090f25406ffc5ab0aa4ed69219e4420d71afa
5
+ SHA512:
6
+ metadata.gz: a3e7722619acd6b317df6a199e36de59557ecb004038a2266fe14beedb3ca33dc3bc6e513af763ff54283ee1706cefaf8075cc8d827276c421bcdc0b52cce5ad
7
+ data.tar.gz: fe208c74230e6d57e2ec349dd9da73f92527aa1c85d720de8218aa7bc5b593b74e69ef63503e81ef511de686a42fe2ca64c1d5937266bca444adbb1181413b5f
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.2.5
7
+ before_install: gem install bundler -v 1.16.6
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 superlanding-ruby.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ superlanding (0.1.0)
5
+ activesupport
6
+ rest-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ concurrent-ruby (1.1.3)
17
+ domain_name (0.5.20180417)
18
+ unf (>= 0.0.5, < 1.0.0)
19
+ http-cookie (1.0.3)
20
+ domain_name (~> 0.5)
21
+ i18n (1.1.1)
22
+ concurrent-ruby (~> 1.0)
23
+ mime-types (3.2.2)
24
+ mime-types-data (~> 3.2015)
25
+ mime-types-data (3.2018.0812)
26
+ minitest (5.11.3)
27
+ netrc (0.11.0)
28
+ rake (10.5.0)
29
+ rest-client (2.0.2)
30
+ http-cookie (>= 1.0.2, < 2.0)
31
+ mime-types (>= 1.16, < 4.0)
32
+ netrc (~> 0.8)
33
+ thread_safe (0.3.6)
34
+ tzinfo (1.2.5)
35
+ thread_safe (~> 0.1)
36
+ unf (0.1.4)
37
+ unf_ext
38
+ unf_ext (0.0.7.5)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.16)
45
+ minitest (~> 5.0)
46
+ rake (~> 10.0)
47
+ superlanding!
48
+
49
+ BUNDLED WITH
50
+ 1.16.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 eddie
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,6 @@
1
+ # 使用方式
2
+
3
+ ```ruby
4
+ @client = SuperLanding::Client.new("MERCHANT_NO", "ACCESS_KEY")
5
+ @items = @client.statistic_items!([28]) # member_base_ids
6
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:t) do |t|
5
+ t.libs << "spec"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["spec/**/*_spec.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "superlanding/ruby"
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,15 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require "active_support/core_ext/module/delegation"
4
+ require "super_landing/version"
5
+ require "super_landing/client"
6
+ require "super_landing/api/base"
7
+ require "super_landing/api/order"
8
+ require "super_landing/api/statistic_items"
9
+ require "super_landing/api/response/base"
10
+ require "super_landing/api/response/order"
11
+ require "super_landing/api/response/statistic_items"
12
+
13
+ module SuperLanding
14
+ BASE_URL = "https://www.super-landing.com/api"
15
+ end
@@ -0,0 +1,52 @@
1
+ module SuperLanding
2
+ module API
3
+ class Base
4
+
5
+ attr_accessor :base_url, :merchant_no, :access_key
6
+
7
+ def initialize(merchant_no, access_key, base_url=nil)
8
+ @merchant_no = merchant_no
9
+ @access_key = access_key
10
+ @base_url = base_url.nil? ? SuperLanding::BASE_URL : base_url
11
+ end
12
+
13
+ protected
14
+
15
+ def post(path)
16
+ RestClient.post(uri(path).to_s, post_data)
17
+ rescue RestClient::ExceptionWithResponse => e
18
+ e.response
19
+ end
20
+
21
+ def get(path)
22
+ RestClient.get(uri(path).to_s)
23
+ rescue RestClient::ExceptionWithResponse => e
24
+ e.response
25
+ end
26
+
27
+ # [GET] query string params
28
+ def params
29
+ {}
30
+ end
31
+
32
+ # [POST]
33
+ def post_data
34
+ {}
35
+ end
36
+
37
+ private
38
+
39
+ def uri(path)
40
+ uri = URI.parse("#{base_url}#{path}").tap { |u| u.query = query_auth_params }
41
+ end
42
+
43
+ def query_auth_params
44
+ URI.encode_www_form(auth_params.merge(params))
45
+ end
46
+
47
+ def auth_params
48
+ { merchant_no: merchant_no, access_key: access_key }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,7 @@
1
+ module SuperLanding
2
+ module API
3
+ class Order < Base
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module SuperLanding
2
+ module API
3
+ module Response
4
+ class Base
5
+ attr_accessor :code, :raw_data, :data
6
+
7
+ def initialize(raw_data, code)
8
+ @raw_data = raw_data
9
+ @code = code
10
+ @data = JSON.parse(raw_data)
11
+ end
12
+
13
+ def auth?
14
+ code == 200
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module SuperLanding
2
+ module API
3
+ module Response
4
+ class Order < Base
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ module SuperLanding
2
+ module API
3
+ module Response
4
+ class StatisticItems < Base
5
+ attr_accessor :items
6
+
7
+ delegate :length, to: :items
8
+ delegate :each, to: :items
9
+ delegate :each_with_index, to: :items
10
+ delegate :map, to: :items
11
+
12
+ Item = Struct.new(:code, :title, :owe_qty, :day3, :day7, :day30, :day3_avg, :day7_avg, :day30_avg)
13
+
14
+ def initialize(*)
15
+ super
16
+ @items = auth? ? data.map { |item| Item.new(item.values) } : []
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ module SuperLanding
2
+ module API
3
+ class StatisticItems < Base
4
+
5
+ attr_accessor :ids
6
+
7
+ def get!(ids)
8
+ @ids = ids
9
+ response = get('/statistic/items.json')
10
+ Response::StatisticItems.new(response.body, response.code)
11
+ end
12
+
13
+ def params
14
+ { member_base_ids: ids }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module SuperLanding
2
+ class Client
3
+ attr_accessor :base_url, :merchant_no, :access_key
4
+
5
+ def initialize(merchant_no, access_key, base_url=nil)
6
+ @merchant_no = merchant_no
7
+ @access_key = access_key
8
+ @base_url = base_url
9
+ end
10
+
11
+ def statistic_items!(ids)
12
+ API::StatisticItems.new(merchant_no, access_key, base_url).get!(ids)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module SuperLanding
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "super_landing/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "superlanding"
8
+ spec.version = SuperLanding::VERSION
9
+ spec.authors = ["Eddie Li"]
10
+ spec.email = ["eddie@super-landing.com"]
11
+
12
+ spec.summary = %q{一頁商店 SuperLanding API Client (ruby implementation)}
13
+ spec.description = %q{一頁商店 SuperLanding API Client (ruby implementation)}
14
+ spec.homepage = "https://github.com/superlanding/superlanding-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
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.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ spec.add_dependency "rest-client"
30
+ spec.add_dependency "activesupport"
31
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: superlanding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eddie Li
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-21 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: "一頁商店 SuperLanding API Client (ruby implementation)"
84
+ email:
85
+ - eddie@super-landing.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/super_landing.rb
100
+ - lib/super_landing/api/base.rb
101
+ - lib/super_landing/api/order.rb
102
+ - lib/super_landing/api/response/base.rb
103
+ - lib/super_landing/api/response/order.rb
104
+ - lib/super_landing/api/response/statistic_items.rb
105
+ - lib/super_landing/api/statistic_items.rb
106
+ - lib/super_landing/client.rb
107
+ - lib/super_landing/version.rb
108
+ - superlanding-ruby.gemspec
109
+ homepage: https://github.com/superlanding/superlanding-ruby
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.4.8
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: "一頁商店 SuperLanding API Client (ruby implementation)"
133
+ test_files: []