shiny-sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +6 -0
  4. data/lib/shiny_sdk.rb +67 -0
  5. data/shiny_sdk.gemspec +14 -0
  6. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ee39d9d2a94e37f2b00feb70b58c5a0f119403a
4
+ data.tar.gz: a9d53d30f8f1fe139a58ca0dffdd657d000705bf
5
+ SHA512:
6
+ metadata.gz: 419dde01f47ad477467888114188faeb6af59a74ae64bf094c6eea3693e25bca27a54e80a65da14016014b37038feb6f287b35f0f8bf7ad7a7eae7e8dc920ce9
7
+ data.tar.gz: cecfdac5bddd2f8980f2eddc245ec0fd6061f7a50f20f7efd2e8bd199f028b908d8c3dd2539f869f8f856c4b070ecf3cc40246f34ef988f23d571dca4d00b689
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Shiny
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Shiny Ruby SDK
2
+
3
+ ## 安装
4
+ ```bash
5
+ gem install shiny-sdk
6
+ ```
data/lib/shiny_sdk.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'digest/md5'
4
+ require 'digest/sha1'
5
+ require 'rest-client'
6
+
7
+ class ShinyError < StandardError
8
+ def initialize(message)
9
+ super
10
+ end
11
+ end
12
+
13
+ class Shiny
14
+ def initialize(api_key, api_secret_key, api_host)
15
+ @API_KEY = api_key
16
+ @API_SECRET_KEY = api_secret_key
17
+ @API_HOST = api_host
18
+ end
19
+
20
+ def add(spider_name, level, data=nil, hash=false)
21
+ # 添加数据项
22
+ if data.nil?
23
+ data = {}
24
+ end
25
+
26
+ url = @API_HOST + '/Data/add'
27
+
28
+ payload = {'api_key' => @API_KEY}
29
+
30
+ event = {"level": level, "spiderName": spider_name}
31
+
32
+ # 如果没有手动指定Hash,将会把data做一次md5生成hash
33
+ begin
34
+ if hash
35
+ event['hash'] = hash
36
+ else
37
+ event['hash'] = Digest::MD5.hexdigest(data.to_json)
38
+ end
39
+ rescue
40
+ ShinyError.new('Fail to generate hash.')
41
+ end
42
+
43
+ event['data'] = data
44
+
45
+ payload['sign'] = Digest::SHA1.hexdigest(@API_KEY + @API_SECRET_KEY + event.to_json)
46
+
47
+ payload["event"] = event.to_json
48
+
49
+ begin
50
+ response = RestClient.post(url, payload)
51
+ return JSON.parser(response.body)
52
+ rescue => e
53
+ ShinyError.new('Network error:' + e.to_s)
54
+ end
55
+ end
56
+
57
+ def recent
58
+ # 获取最新项目
59
+ url = @API_HOST + '/Data/recent'
60
+ begin
61
+ response = RestClient.get(url)
62
+ return JSON.parse(response.body)
63
+ rescue => e
64
+ ShinyError.new('Network error:' + e.to_s)
65
+ end
66
+ end
67
+ end
data/shiny_sdk.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'shiny-sdk'
3
+ s.version = '0.0.1'
4
+ s.date = `git log --pretty="%ai" -n 1`.split(" ").first
5
+ s.summary = "Shiny SDK"
6
+ s.description = "Shiny Ruby SDK"
7
+ s.authors = ["Koell"]
8
+ s.email = 'i@wug.moe'
9
+ s.files = `git ls-files -z`.split("\0")
10
+ s.homepage = 'https://shiny.kotori.moe'
11
+ s.license = 'MIT'
12
+ s.add_dependency(%q<rest-client>, ["~> 2.0.0"])
13
+ s.required_ruby_version = '>= 2.0.0'
14
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shiny-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Koell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-20 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: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ description: Shiny Ruby SDK
28
+ email: i@wug.moe
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - lib/shiny_sdk.rb
36
+ - shiny_sdk.gemspec
37
+ homepage: https://shiny.kotori.moe
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.0.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.5.1
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Shiny SDK
61
+ test_files: []