hik_openapi 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: 02216e0101d908c23f97098fc96d672e4296b4ab479ab2b83fe74b2c037e9a37
4
+ data.tar.gz: d68c0dcf1975b3544d688ffabc02385ea9698ba7d3357c50e98f9b88bc219af5
5
+ SHA512:
6
+ metadata.gz: '0093f20b04cb3a142ec47d797c155b8f190121b675a1370423462b8b53d68d9b4f208b467fc9f4d745fc1e1dc0cde4ba5633a9c1ade2ae9b0264ef93f3c7d627'
7
+ data.tar.gz: 779eccde8d617f7a902d7b31e72d28d4220a6c1505c8fda3fbf1482f643c02c73b4954ec13310ae500b0d6d5e90958b310ee7c9c397fe2d0fbd7f328b370af11
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /vendor/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hik_openapi.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hik_openapi (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ rake (12.3.3)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.2)
16
+ rspec-support (~> 3.9.3)
17
+ rspec-expectations (3.9.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ hik_openapi!
30
+ rake (~> 12.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.1.4
@@ -0,0 +1,37 @@
1
+ # HikOpenapi
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/hik_openapi`. 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 'hik_openapi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hik_openapi
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hik_openapi.
36
+
37
+ # hik_openapi
@@ -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,28 @@
1
+ require_relative 'lib/hik_openapi/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'hik_openapi'
5
+ spec.version = HikOpenapi::VERSION
6
+ spec.authors = ['palytoxin']
7
+ spec.email = ['sxty32@gmail.com']
8
+
9
+ spec.summary = 'hikvision openapi for ruby.'
10
+ spec.description = 'hikvision openapi for ruby.'
11
+ spec.homepage = 'https://github.com/palytoxin/hik_openapi'
12
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
13
+
14
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/palytoxin/hik_openapi'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/palytoxin/hik_openapi'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'hik_openapi/version'
4
+ require 'hik_openapi/configuration'
5
+ require 'hik_openapi/api'
6
+ require 'hik_openapi/result'
7
+
8
+ module HikOpenapi
9
+ class Error < StandardError; end
10
+
11
+ def self.config
12
+ return @config if defined?(@config)
13
+
14
+ @config = Configuration.new
15
+ @config
16
+ end
17
+
18
+ def self.setup
19
+ yield config
20
+ end
21
+
22
+ def self.api
23
+ Api
24
+ end
25
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module HikOpenapi
6
+ module Api
7
+ class << self
8
+ def get
9
+ # TODO
10
+ puts 'WIP'
11
+ end
12
+
13
+ def post(path, body)
14
+ uri = URI(HikOpenapi.config.host)
15
+ uri.merge!(path)
16
+
17
+ https = Net::HTTP.new(uri.host, uri.port)
18
+ https.use_ssl = true
19
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
20
+ headers = init_header('POST', uri.path)
21
+ # headers.transform_values! { |v| v.force_encoding('iso-8859-1') }
22
+
23
+ begin
24
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
25
+ request.body = body.to_json
26
+ res = https.request(request)
27
+
28
+ result = HikOpenapi::Result.new
29
+ result.code = res.code
30
+ result.body = JSON.parse(res.body.force_encoding('utf-8'))
31
+ result.origin = res
32
+ result
33
+ rescue StandardError => e
34
+ result = HikOpenapi::Result.new
35
+ result.error = HikOpenapi::Error.new(e)
36
+ result
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def init_header(method, path)
43
+ headers = {
44
+ 'Content-Type': 'application/json',
45
+ "Accept": '*/*',
46
+ 'x-ca-timestamp': (Time.now.to_f * 1000).to_i.to_s,
47
+ 'x-ca-nonce': SecureRandom.uuid,
48
+ 'x-ca-key': HikOpenapi.config.app_key
49
+ }
50
+
51
+ headers.merge({
52
+ "x-ca-signature": sign(method, path, headers)
53
+ })
54
+ end
55
+
56
+ def sign(method, path, headers)
57
+ sign_str = headers.reject { |a| a.to_s.start_with?('x-ca') }.values.sort
58
+ sign_str = sign_str.unshift(method).push(path).join("\n")
59
+
60
+ enc = Base64.encode64(
61
+ OpenSSL::HMAC.digest(
62
+ OpenSSL::Digest.new('sha256'),
63
+ HikOpenapi.config.app_secret,
64
+ sign_str
65
+ )
66
+ ).strip
67
+ enc
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HikOpenapi
4
+ class Configuration
5
+ attr_accessor :host
6
+ attr_accessor :app_key
7
+ attr_accessor :app_secret
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HikOpenapi
4
+ class Result
5
+ attr_accessor :code
6
+ attr_accessor :body
7
+ attr_accessor :origin
8
+ attr_accessor :error
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HikOpenapi
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hik_openapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - palytoxin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: hikvision openapi for ruby.
14
+ email:
15
+ - sxty32@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - README.md
26
+ - Rakefile
27
+ - hik_openapi.gemspec
28
+ - lib/hik_openapi.rb
29
+ - lib/hik_openapi/api.rb
30
+ - lib/hik_openapi/configuration.rb
31
+ - lib/hik_openapi/result.rb
32
+ - lib/hik_openapi/version.rb
33
+ homepage: https://github.com/palytoxin/hik_openapi
34
+ licenses: []
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ homepage_uri: https://github.com/palytoxin/hik_openapi
38
+ source_code_uri: https://github.com/palytoxin/hik_openapi
39
+ changelog_uri: https://github.com/palytoxin/hik_openapi
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.2
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: hikvision openapi for ruby.
59
+ test_files: []