admqr_knife 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 06b0ffb1b6364cd47bf389fc0d89ae5176718656ae0eed5f24605466ef94ff81
4
+ data.tar.gz: ffecc85d0926b3cf57816b4e27614210dd855929dffae768151d901bb26e3e9f
5
+ SHA512:
6
+ metadata.gz: 9b768ac52b9cd58afa860ebb84e0f49ca17c5fce6b763dacd24f5fa7f66b18d1c05742961aaccc686f939fc6a4a1c86b5ecadbf1d378c7d7fe8e604d9ffca283
7
+ data.tar.gz: 77188b9318160d324aeca149be0872e5f7914bd850f31cb067f19f85d8e92de0666827088fc8e635cfb99c571f0312229a96d212875929d0d15c9980eb87e2a5
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ TAGS
13
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -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 atpking@gmail.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,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in admqr_knife.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ admqr_knife (0.1.0)
5
+ api_tools
6
+ thor
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ api_tools (0.1.0)
12
+ multi_json
13
+ rest-client (~> 2.0)
14
+ byebug (11.0.1)
15
+ diff-lcs (1.3)
16
+ domain_name (0.5.20190701)
17
+ unf (>= 0.0.5, < 1.0.0)
18
+ http-accept (1.7.0)
19
+ http-cookie (1.0.3)
20
+ domain_name (~> 0.5)
21
+ mime-types (3.3)
22
+ mime-types-data (~> 3.2015)
23
+ mime-types-data (3.2019.1009)
24
+ multi_json (1.14.1)
25
+ netrc (0.11.0)
26
+ rake (10.5.0)
27
+ rest-client (2.1.0)
28
+ http-accept (>= 1.7.0, < 2.0)
29
+ http-cookie (>= 1.0.2, < 2.0)
30
+ mime-types (>= 1.16, < 4.0)
31
+ netrc (~> 0.8)
32
+ rspec (3.9.0)
33
+ rspec-core (~> 3.9.0)
34
+ rspec-expectations (~> 3.9.0)
35
+ rspec-mocks (~> 3.9.0)
36
+ rspec-core (3.9.0)
37
+ rspec-support (~> 3.9.0)
38
+ rspec-expectations (3.9.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.9.0)
41
+ rspec-mocks (3.9.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.9.0)
44
+ rspec-support (3.9.0)
45
+ thor (0.20.3)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.7.6)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ admqr_knife!
55
+ bundler (~> 2.0)
56
+ byebug
57
+ rake (~> 10.0)
58
+ rspec (~> 3.0)
59
+
60
+ BUNDLED WITH
61
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 atpking
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.
@@ -0,0 +1,90 @@
1
+ # AdmqrKnife
2
+
3
+ 通过第三方转发统计信息给毛驴短链, 这样就可以做到不用用户访问访问, 将用户的信息直接转发即可
4
+
5
+ 特别适合与做漏斗
6
+
7
+ 比如曝光页面用毛驴做了统计
8
+
9
+ 就可以在注册的时候再次发起一次统计, 即可得出曝光转化比
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'admqr_knife'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install admqr_knife
26
+
27
+ ## Usage
28
+
29
+ ### 命令行方式
30
+
31
+ `admqr_visit record 标签名称 -t API_TOKEN`
32
+
33
+ 更多参数可以使用 `admqr_visit help record` 进行查看
34
+
35
+
36
+ ### gem 集成
37
+
38
+ 1. 在 rails 里 initializers 中配置
39
+
40
+ ```ruby
41
+ AdmqrKnife.init(API_TOKEN)
42
+ ```
43
+
44
+ 2. 在需要记录的地方使用如下语法记录
45
+
46
+ ```ruby
47
+ AdmqrKnife.visit unique_code: "唯一标记",
48
+ ua: ua, # UA , 可不传
49
+ referer: referer, # 来自于 , 可不传
50
+ tag: tag, # 分组名 , 可不传
51
+ new_to_visit: new_to_visit, # 是否是今日首次访问 , 可不传, 默认是
52
+ remote_ip: remote_ip # "用户IP"
53
+ ```
54
+
55
+ ### 直接发请求或集成第三方
56
+
57
+ 这种使用方式不需要安装这个gem
58
+
59
+ ```
60
+ curl -X POST \
61
+ https://www.admqr.com/apic/v1 \
62
+ -H 'Content-Type: application/json' \
63
+ -d '{
64
+ "api_token": "你的API_TOKEN",
65
+ "unique_code": "自己取的唯一标志",
66
+ "tag": "分组名, 可以不传",
67
+ "client_ua": "用户UA, 可以不传",
68
+ "referer": "来自于, 可以不传",
69
+ "new_to_visit": 是否是首次访问 true or false, 可以不传, 默认为true
70
+ "remote_ip": '用户的ip, 可以不传'
71
+ }'
72
+ ```
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ 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).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/admqr_knife. 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.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the AdmqrKnife project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/admqr_knife/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "admqr_knife/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "admqr_knife"
7
+ spec.version = AdmqrKnife::VERSION
8
+ spec.authors = ["atpking"]
9
+ spec.email = ["atpking@gmail.com"]
10
+
11
+ spec.summary = 'send vsist record to admqr service'
12
+ spec.description = 'send vsist record to admqr service'
13
+ spec.homepage = "https://www.admqr.com"
14
+ spec.license = "MIT"
15
+
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "byebug"
32
+
33
+ spec.add_dependency 'api_tools'
34
+ spec.add_dependency 'thor'
35
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "admqr_knife"
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__)
@@ -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,36 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'thor'
5
+ # require 'byebug'
6
+ require_relative '../lib/admqr_knife'
7
+
8
+
9
+ class AdmqrVisitCLI < Thor
10
+ desc 'record', 'record a visit data'
11
+ option :api_token, :aliases => "-t", required: true, desc: "API TOKEN"
12
+ option :ua, desc: "visitor's user agent"
13
+ option :referer, desc: 'visitor from '
14
+ option :tag, desc: 'project name'
15
+ option :new_to_visit, type: :boolean, desc: 'is a new visit', default: true
16
+ def record(unique_code)
17
+ AdmqrKnife.init(options[:api_token])
18
+ AdmqrKnife.visit(unique_code: unique_code,
19
+ ua: options[:ua],
20
+ referer: options[:referer],
21
+ tag: options[:tag],
22
+ new_to_visit: options[:new_to_visit],
23
+ remote_ip: options[:remote_ip])
24
+ AdmqrKnife.logger.debug("ok!")
25
+ end
26
+
27
+ desc 'help', 'Describe available commands or one specific command (aliases: `h`).'
28
+ map Thor::HELP_MAPPINGS => :help
29
+ def help(command = nil, subcommand = false)
30
+ super
31
+ end
32
+
33
+
34
+ end
35
+
36
+ AdmqrVisitCLI.start(ARGV)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'admqr_knife/version'
4
+ require 'api_tools'
5
+ # require 'byebug'
6
+ require_relative './admqr_knife/cube_service'
7
+
8
+ module AdmqrKnife
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ class << self
12
+ attr_accessor :knife_api_token, :knife_base_uri, :logger
13
+
14
+ def init(api_token = nil, options = {})
15
+ @knife_api_token = api_token || ENV['ADMQR_KNIFE_API_TOKEN']
16
+ @knife_base_uri = ENV['KNIFE_BASE_URI'] || 'https://www.admqr.com/apic/v1/'
17
+ @logger = options[:logger] || select_logger
18
+ end
19
+
20
+ def api_token
21
+ @knife_api_token
22
+ end
23
+
24
+ def visit(unique_code:, **options)
25
+ raise 'unique_code 不能为空' if unique_code.to_s == ''
26
+
27
+ ua = options[:ua]
28
+ referer = options[:referer]
29
+ tag = options[:tag]
30
+ new_to_visit = options[:new_to_visit]
31
+ remote_ip = options[:remote_ip]
32
+ CubeService.post('/api/knifes/statis',
33
+ { unique_code: unique_code,
34
+ client_ua: ua,
35
+ referer: referer,
36
+ tag: tag,
37
+ new_to_visit: new_to_visit,
38
+ remote_ip: remote_ip }.reject! { |_k, v| v.nil? })
39
+ rescue StandardError => e
40
+ logger.error e.message
41
+ end
42
+
43
+ private
44
+
45
+ def select_logger
46
+ return Rails.logger if defined? Rails
47
+
48
+ Logger.new(STDOUT)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AdmqrKnife
4
+ class CubeService < DefaultRest
5
+ class << self
6
+ def basic_url
7
+ AdmqrKnife.knife_base_uri
8
+ end
9
+
10
+ def base_params
11
+ {
12
+ api_token: AdmqrKnife.knife_api_token,
13
+ gem_version: AdmqrKnife::VERSION
14
+ }
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module AdmqrKnife
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: admqr_knife
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - atpking
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-02 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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.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.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: api_tools
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
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: send vsist record to admqr service
98
+ email:
99
+ - atpking@gmail.com
100
+ executables:
101
+ - admqr_visit
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - admqr_knife.gemspec
115
+ - bin/console
116
+ - bin/setup
117
+ - exe/admqr_visit
118
+ - lib/admqr_knife.rb
119
+ - lib/admqr_knife/cube_service.rb
120
+ - lib/admqr_knife/version.rb
121
+ homepage: https://www.admqr.com
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ homepage_uri: https://www.admqr.com
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.0.3
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: send vsist record to admqr service
145
+ test_files: []