shanon 0.1.2

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
+ SHA1:
3
+ metadata.gz: c1474207b017d79213bc4ea7d893c602097cac62
4
+ data.tar.gz: a88bdc20f92aa93433b843faec3d9a956aa60c24
5
+ SHA512:
6
+ metadata.gz: fdcd18eb93675f19d4f50f28cd418f1f04be8c843135d6c9dc8a0bb5571d02a3bef535c026d65a45c626003d46d87091121aaa1a75db94519de044a45b76e4da
7
+ data.tar.gz: 4c82c2b56590b6d405b095cd21fad4533e89b02a07c07edd1ef182f18b1b8adeac8248796388dfc3ebc94249a630792e9f8cb206b876c888d4283ab32a7a470d
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
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install:
6
+ - gem update --system
7
+ - gem update bundler
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at github@takuyan.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
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 shanon-ruby.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Takuya Kato
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,56 @@
1
+ # Shanon
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shanon`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'shanon'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install shanon
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ Shanon.configure do |config|
27
+ config.api_key = 'your_consumer_api_key'
28
+ config.fqdn = 'your-consumer-name.smktg.jp'
29
+ config.password = 'your_consumer_password'
30
+ config.secret_key = 'your_consumer_secret_key'
31
+ end
32
+
33
+ client = Shanon::Clients::AuthenticationClient.new
34
+ puts client.get # => token
35
+
36
+ client = Shanon::Clients::VisitorClient.new
37
+ puts client.get # => visitors
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/takuyan/shanon-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
53
+
54
+ ## Code of Conduct
55
+
56
+ Everyone interacting in the Shanon project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/takuyan/shanon-ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.warning = true
9
+ t.verbose = true
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'shanon/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,55 @@
1
+ require 'digest/sha1'
2
+ require 'openssl'
3
+
4
+ module Shanon
5
+ class AbstractClient
6
+ attr_reader :secrets, :conn, :token
7
+
8
+ def initialize
9
+ @secrets = get_secrets
10
+ @conn = build_client
11
+ @token = get_token
12
+ end
13
+
14
+ private
15
+
16
+ def get_secrets
17
+ {
18
+ api_key: Shanon.config.api_key,
19
+ fqdn: Shanon.config.fqdn,
20
+ password: Shanon.config.password,
21
+ secret_key: Shanon.config.secret_key
22
+ }
23
+ end
24
+
25
+ def build_client
26
+ fqdn = secrets[:fqdn]
27
+ host = %(https://#{fqdn})
28
+
29
+ ::Faraday.new(url: host) do |builder|
30
+ builder.use Faraday::Request::UrlEncoded
31
+ builder.use Faraday::Response::Logger
32
+ builder.use Faraday::Adapter::NetHttp
33
+ end
34
+ end
35
+
36
+ def get_token
37
+ # override by Authenticatable
38
+ end
39
+
40
+ def params_with_signature(opts={})
41
+ seeds = { api_key: secrets[:api_key] }.merge!(opts)
42
+ seeds.merge!(token: token) if token
43
+
44
+ base = seeds.sort.reduce('') do |s, (k, v)|
45
+ s.concat %(#{k}#{v})
46
+ end
47
+
48
+ seeds.merge!({ api_sig: get_signature(base) })
49
+ end
50
+
51
+ def get_signature(base)
52
+ ::OpenSSL::HMAC.hexdigest('sha1', secrets[:secret_key], base)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ module Shanon
2
+ module Authenticatable
3
+ def get_token
4
+ @token = Shanon::Clients::AuthenticationClient.new.get
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module Shanon
2
+ module Clients
3
+ class AuthenticationClient < Shanon::AbstractClient
4
+ PATH = '/services/rest/authentication'.freeze
5
+
6
+ def get
7
+ params = params_with_signature(password: secrets[:password])
8
+ response = conn.get(PATH, params)
9
+ parse(response.body)
10
+ end
11
+
12
+ private
13
+
14
+ def parse(xml)
15
+ ::Ox.parse(xml).Response.Token.text
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ module Shanon
2
+ module Clients
3
+ class VisitorClient < Shanon::AbstractClient
4
+ include Authenticatable
5
+
6
+ PATH = '/services/rest/visitor'.freeze
7
+
8
+ # opts = {
9
+ # search_key1: 'DateRegist',
10
+ # search_operator1: 'lt',
11
+ # search_value1: '2018-01-01T00:00:00+09:00'
12
+ # }
13
+ def get(opts={})
14
+ params = params_with_signature(opts)
15
+ response = conn.get PATH, params
16
+ parse(response.body)
17
+ end
18
+
19
+ private
20
+
21
+ def parse(xml)
22
+ ::Ox.parse(xml)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ module Shanon
2
+ # Configures global settings for Shanon
3
+ # Shanon.configure do |config|
4
+ # config.api_key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
5
+ # config.fqdn = 'aaaa-bbbb.smktg.jp'
6
+ # config.password = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
7
+ # config.secret_key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
8
+ # end
9
+ class << self
10
+ def configure
11
+ yield config
12
+ end
13
+
14
+ def config
15
+ @_config ||= Config.new
16
+ end
17
+ end
18
+
19
+ class Config
20
+ attr_accessor :api_key, :fqdn, :password, :secret_key
21
+ attr_writer :param_name
22
+
23
+ def initialize
24
+ @api_key = nil
25
+ @fqdn = nil
26
+ @password = nil
27
+ @secret_key = nil
28
+ end
29
+
30
+ # If param_name was given as a callable object, call it when returning
31
+ def param_name
32
+ @param_name.respond_to?(:call) ? @param_name.call : @param_name
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Shanon
2
+ VERSION = '0.1.2'
3
+ end
data/lib/shanon.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'shanon/version'
2
+
3
+ require 'shanon/config'
4
+ require 'shanon/abstract_client'
5
+ require 'shanon/authenticatable'
6
+ require 'shanon/clients/authentication_client'
7
+ require 'shanon/clients/visitor_client'
8
+
9
+ module Shanon
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'shanon/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'shanon'
7
+ spec.version = Shanon::VERSION
8
+ spec.authors = ['Takuya Kato']
9
+ spec.email = ['g@takuyan.com']
10
+
11
+ spec.summary = %q{Client for accessing Shanon Marketing Platform APIs}
12
+ spec.description = %q{Client for accessing Shanon Marketing Platform APIs}
13
+ spec.homepage = 'https://github.com/takuyan/shanon-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'faraday'
24
+ spec.add_dependency 'ox'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'test-unit'
29
+ spec.add_development_dependency 'webmock'
30
+ spec.add_development_dependency 'pry-byebug'
31
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shanon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Takuya Kato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-05 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'
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: ox
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
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: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Client for accessing Shanon Marketing Platform APIs
112
+ email:
113
+ - g@takuyan.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - CODE_OF_CONDUCT.md
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/shanon.rb
128
+ - lib/shanon/abstract_client.rb
129
+ - lib/shanon/authenticatable.rb
130
+ - lib/shanon/clients/authentication_client.rb
131
+ - lib/shanon/clients/visitor_client.rb
132
+ - lib/shanon/config.rb
133
+ - lib/shanon/version.rb
134
+ - shanon-ruby.gemspec
135
+ homepage: https://github.com/takuyan/shanon-ruby
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.13
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Client for accessing Shanon Marketing Platform APIs
159
+ test_files: []