yilian 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f32587685eb20196486f225d5bb99f4e2bdf827
4
+ data.tar.gz: 12e53a39f43221e284089b8558a525f4cb9c62f0
5
+ SHA512:
6
+ metadata.gz: b6e55dbd175b34c2a0ac0a46c353fedbb052779cd1ac6c35d28c7cdaef50fc49b2fbf625e097dbdfab5a162fd4c54ee32e5ddde222b4333121aef5f86efc8268
7
+ data.tar.gz: b912927e8a6abe5b386dd3175113017e28f438e5e226a992b63c5ef784fc936d3eed976028a6c744b9a2b99bbaa30b0c563c193e93c8a5824e81011cb6b9614f
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yilian.gemspec
4
+ gemspec
@@ -0,0 +1,62 @@
1
+ # 易联云打印
2
+
3
+ * [易联云](http://www.10ss.net/)打印 ruby sdk
4
+
5
+ ## Installation
6
+
7
+ Now, Install from github only
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yilian'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yilian
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ # usage in test.rb
27
+
28
+ require 'yilian'
29
+
30
+ config = {
31
+ api_key: '',
32
+ partner: '',
33
+ username: '',
34
+ machine_code: '',
35
+ msign: '',
36
+ printname: '',
37
+ }
38
+
39
+ print = Yilian::Print.new(config)
40
+
41
+ opts ={
42
+ machine_code: config[:machine_code],
43
+ msign: config[:msign],
44
+ content: '打印测试....'
45
+ }
46
+
47
+ p print.print(opts)
48
+
49
+ ```
50
+
51
+ ## Development
52
+
53
+ 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.
54
+
55
+ 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).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wikimo/yilian.
60
+
61
+
62
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yilian"
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
@@ -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,83 @@
1
+ require "yilian/version"
2
+ require "hash-utils/hash"
3
+ require 'uri'
4
+ require 'digest/md5'
5
+ require 'rest-client'
6
+ require 'json'
7
+
8
+ module Yilian
9
+ class Print
10
+ GATEWAY = 'http://open.10ss.net:8888'
11
+
12
+ # options = {
13
+ # api_key:
14
+ # partner:
15
+ # username:
16
+ # }
17
+ def initialize(options)
18
+ @api_key = options[:api_key]
19
+ @partner = options[:partner]
20
+ @username = options[:username]
21
+ end
22
+
23
+ # 添加打印机
24
+ def create(opts)
25
+ params ={
26
+ partner: opts[:partner] || @partner,
27
+ machine_code: opts[:machine_code],
28
+ mobilephone: opts[:mobilephone] || '',
29
+ username: opts[:username] || @username,
30
+ printname: opts[:printname],
31
+ }
32
+
33
+ params[:sign] = self.sign params, opts[:msign]
34
+ params[:msign] = opts[:msign]
35
+
36
+ self.api_request params, 'addprint.php'
37
+ end
38
+
39
+ # 删除打印机
40
+ def destroy(opts)
41
+ params ={
42
+ partner: opts[:partner] || @partner,
43
+ machine_code: opts[:machine_code]
44
+ }
45
+
46
+ params[:sign] = self.sign params, opts[:msign]
47
+ self.api_request params, 'removeprint.php'
48
+ end
49
+
50
+ # 打印内容
51
+ def print(opts)
52
+ params ={
53
+ partner: opts[:partner] || @partner,
54
+ machine_code: opts[:machine_code],
55
+ time: Time.now.to_i
56
+ }
57
+
58
+ params[:sign] = self.sign params, opts[:msign]
59
+ params[:content] = opts[:content]
60
+
61
+ response = self.api_request params
62
+ JSON.parse response
63
+ end
64
+
65
+ def api_request(params, endpoint = '')
66
+ response = RestClient.post "#{GATEWAY}/#{endpoint}", self.params_str(params), content_type: 'json', accept: 'json'
67
+ return response.body if response.code == 200
68
+
69
+ false
70
+ end
71
+
72
+ def sign(params, msign)
73
+ params = params.ksort
74
+ params_str = params.map{|k, v| "#{k}#{v}"}.join
75
+ Digest::MD5.hexdigest("#{@api_key}#{params_str}#{msign}").upcase
76
+ end
77
+
78
+ def params_str(params)
79
+ params.map{|k,v| "#{k}=#{v}"}.join('&')
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module Yilian
2
+ VERSION = "0.1.0"
3
+ end
data/test.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "bundler/setup"
2
+ require "yilian"
3
+
4
+ config = {
5
+ api_key: '',
6
+ partner: '',
7
+ username: '',
8
+ machine_code: '',
9
+ msign: '',
10
+ printname: '',
11
+ }
12
+
13
+ print = Yilian::Print.new(config)
14
+
15
+ opts ={
16
+ machine_code: config[:machine_code],
17
+ printname: config[:printname],
18
+ msign: config[:msign]
19
+ }
20
+
21
+ # p print.create(opts)
22
+
23
+ # opts ={
24
+ # machine_code: config[:machine_code],
25
+ # msign: config[:msign]
26
+ # }
27
+
28
+ # p print.destroy(opts)
29
+
30
+ opts ={
31
+ machine_code: config[:machine_code],
32
+ msign: config[:msign],
33
+ content: '打印测试....'
34
+ }
35
+
36
+ p print.print(opts)
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yilian/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yilian"
8
+ spec.version = Yilian::VERSION
9
+ spec.authors = ["wikimo"]
10
+ spec.email = ["gwikimo@gmail.com"]
11
+
12
+ spec.summary = %q{Yilian print sdk.}
13
+ spec.description = %q{Yilian print sdk.}
14
+ spec.homepage = "https://github.com/wikimo/yilian-ruby-sdk"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency 'rest-client'
30
+ spec.add_dependency 'hash-utils'
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.12"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yilian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - wikimo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
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: hash-utils
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.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
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
+ description: Yilian print sdk.
70
+ email:
71
+ - gwikimo@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - bin/console
81
+ - bin/setup
82
+ - lib/yilian.rb
83
+ - lib/yilian/version.rb
84
+ - test.rb
85
+ - yilian.gemspec
86
+ homepage: https://github.com/wikimo/yilian-ruby-sdk
87
+ licenses: []
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.6
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Yilian print sdk.
109
+ test_files: []