qihusem 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50575290ee7fc9ee2010f66bb103b6021f92ec56
4
+ data.tar.gz: 9c17938005198ffb39ea44e5fd3b01dfdc37089c
5
+ SHA512:
6
+ metadata.gz: 1b50e3c1e17e031e5b6f9cfd738e294b61bcfee41251b38754680c05870748d107af85b9668e180ef8534a0dc30b4d8449504d7e2e7f86c7586a59fb56856aab
7
+ data.tar.gz: 9bc00b98808af3506fe071c8c9d21d69150bdfda0e77099a0966955270d494e9c5f6c11dc716a2c2782f8ec6437e45109382159e03152f307a34938f1b370921
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Qihusem
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'qihusem'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install qihusem
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,80 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'pp'
4
+ require 'openssl'
5
+ require 'digest'
6
+
7
+ module Qihusem
8
+ class Base
9
+ def initialize(attrs={})
10
+ @username = attrs[:username]
11
+ @apiSecret = attrs[:apiSecret]
12
+ @apiKey = attrs[:apiKey]
13
+ @password = attrs[:password]
14
+ @debug = attrs[:debug]
15
+
16
+ ps = Digest::MD5.hexdigest(@password)
17
+
18
+ key = @apiSecret[0..15]
19
+ iv = @apiSecret[16..-1]
20
+
21
+ aes = OpenSSL::Cipher::Cipher.new("AES-128-CBC")
22
+ aes.encrypt
23
+ aes.padding = 0
24
+ aes.key = key
25
+ aes.iv = iv
26
+ encrypted = aes.update(ps) << aes.final
27
+ @password = encrypted.unpack('H*').join
28
+
29
+ refresh_token
30
+ end
31
+
32
+ def call(service,method,body=nil,version='1.0',base_uri='https://api.e.360.cn')
33
+ response = {}
34
+
35
+ headers = {
36
+ 'serveToken' => Time.now.to_i.to_s,
37
+ 'apiKey' => @apiKey,
38
+ 'content-type' => 'application/x-www-form-urlencoded'
39
+ }
40
+
41
+ headers['accessToken'] = get_token unless service.to_s == 'account' && method.to_s == 'clientLogin'
42
+
43
+ 5.times do |i|
44
+ response = HTTParty.post("#{base_uri}/#{version}/#{service}/#{method}?format=json",
45
+ :body => body,
46
+ :headers => headers,
47
+ :verify => false
48
+ )
49
+
50
+ pp response if @debug
51
+
52
+ break # if response['header']['desc'] == 'success'
53
+
54
+ sleep(20*(i+1))
55
+ end
56
+
57
+ response
58
+ end
59
+
60
+ def get_token
61
+ refresh_token if ((Time.now - @access_token_updated_at) > 3600)
62
+ @access_token
63
+ end
64
+
65
+ def refresh_token
66
+ # @access_token = call('account','clientLogin',{:username => @username,:passwd => @password})['accessToken']
67
+ @access_token = HTTParty.post("https://api.e.360.cn/account/clientLogin?format=json",
68
+ :body => {:username => @username,:passwd => @password},
69
+ :headers => {
70
+ 'serveToken' => Time.now.to_i.to_s,
71
+ 'apiKey' => @apiKey,
72
+ 'content-type' => 'application/x-www-form-urlencoded'
73
+ },
74
+ :verify => false
75
+ )['accessToken']
76
+ @access_token_updated_at = Time.now
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module Qihusem
2
+ VERSION = "0.0.1"
3
+ end
data/lib/qihusem.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'qihusem/version'
2
+ require 'qihusem/base'
3
+
4
+ module Qihusem
5
+ def self.new(attrs)
6
+ Base.new(attrs)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qihusem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - MingQian Zhang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-31 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: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Qihu SEM API Client.
56
+ email:
57
+ - zmingqian@qq.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/qihusem/base.rb
63
+ - lib/qihusem/version.rb
64
+ - lib/qihusem.rb
65
+ - README.md
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.0
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Qihu SEM API Client.
90
+ test_files: []