spear-cb-api 0.0.9 → 0.0.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 444695bd38aa39bbc18c5b6581e7f83522dd5348
4
- data.tar.gz: 167956a503f3dd8884f57a3c903999903f69e452
3
+ metadata.gz: 9735511da1987a6ebf6037689ccc8bc1c558111d
4
+ data.tar.gz: e66ee281b2cda1bfc31e7d59c6e26801c9776307
5
5
  SHA512:
6
- metadata.gz: 6b674f8944523d870bd6851168c21d44e2ab3095c0544168032fb308ce9521915bde5ddb9214eb44c39b88cc018183b1dfde278e7aff72f56ea6895ba1f32243
7
- data.tar.gz: f0b6589b4c62deb920a7c9f681e8187e3de511abb26df906b8348a730f930b6d458602fec25f1ff4c7bb4f768a5c469dc758bcf3372dc2a3b68e6e4dbbdd1018
6
+ metadata.gz: b73ecf48f0b22dd010a6f0899f9636f270388bfcafe4af31cb5e1e59c927869d0f4c41176411c627584bb3ed5497a1ce9a2071a8681936b8daffd32bc5fe3a2b
7
+ data.tar.gz: 659f62673de00af1023aab7ce2bad3ce63341cb9bdbd6990999653687ec372d7a408b4ce9e66e39f5b854e0d5d0a50be9d6060ca110b1c34926593a7da73d125
@@ -15,7 +15,15 @@ module Spear
15
15
  end
16
16
  end
17
17
 
18
- class ParametersNotValid < Error; end
18
+ class ParametersNotValid < Error;
19
+ DEFAULT = 'The parameters is invalid.'
20
+
21
+ def initialize(message)
22
+ super(message || DEFAULT)
23
+ end
24
+ end
25
+
19
26
  class NetworkError < Error; end
27
+ class TimeoutError < Error; end
20
28
  class ObjectTypeError < Error; end
21
29
  end
data/lib/spear/request.rb CHANGED
@@ -54,6 +54,8 @@ module Spear
54
54
  end
55
55
  rescue SocketError => e # if the network is disconnected, it'll throw SocketError.
56
56
  raise Spear::NetworkError.new(e.message)
57
+ rescue Timeout::Error => e
58
+ raise Spear::TimeoutError.new(e.message)
57
59
  end
58
60
  end
59
61
 
@@ -27,7 +27,7 @@ module Spear
27
27
  elsif ids.kind_of?(Array)
28
28
  Spear::Request.new(:get, Spear.uri_application_status, {query: {AppDID: ids.join(',')}}).execute
29
29
  else
30
- raise Spear::ParametersNotValid.new('')
30
+ raise Spear::ParametersNotValid.new
31
31
  end
32
32
  end
33
33
 
@@ -31,6 +31,30 @@ module Spear
31
31
  end
32
32
  end
33
33
 
34
+ class ApplicationObject
35
+ attr_accessor :app_did, :is_viewed, :view_date
36
+
37
+ def initialize(app_did, is_viewed, view_date)
38
+ @app_did = app_did
39
+ @is_viewed = 'true'.eql?(is_viewed)
40
+ @view_date = view_date unless view_date.blank?
41
+ end
42
+ end
43
+
44
+ def generate_apps(apps)
45
+ if !apps.nil?
46
+ if apps.kind_of?(Array)
47
+ apps.map {|app|
48
+ ApplicationObject.new(app['ApplicationDID'], app['Viewed'], app['ViewedDate'])
49
+ }
50
+ else # Hash
51
+ [] << ApplicationObject.new(apps['ApplicationDID'], apps['Viewed'], apps['ViewedDate'])
52
+ end
53
+ else
54
+ []
55
+ end
56
+ end
57
+
34
58
  end
35
59
  end
36
60
  end
@@ -2,13 +2,17 @@ module Spear
2
2
  module Structure
3
3
  module Application
4
4
  class State < Structure::Base
5
- attr_accessor :application_list
5
+ include EmbededClass
6
+
7
+ attr_accessor :applications
6
8
 
7
9
  def initialize(response)
8
10
  super(response)
9
- @application_list = @root['ApplicationList']
11
+
12
+ @applications = generate_apps(@root['ApplicationList']['Application']) rescue nil
10
13
  end
11
14
  end
15
+
12
16
  end
13
17
  end
14
18
  end
data/lib/spear/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spear
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/spec/spear_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  describe Spear do
2
2
  before :each do
3
- Spear.config({dev_key: 'xxx', project: 'ExampleApp', use_model: true})
3
+ Spear.config({dev_key: ENV['DEVELOPMENT_KEY'], project: 'ExampleApp', use_model: true})
4
4
  end
5
5
 
6
6
  it "check user existing" do
@@ -50,7 +50,7 @@ describe Spear do
50
50
 
51
51
  it "get application status" do
52
52
  # s = Spear.application_status(['JAWS4L16LFXD7ZL87LLC', 'JAWW63876DWNQGSWZ384', 'JA4M44C77CDSR0QHTRJ6'])
53
- s = Spear.application_status('JAWW63876DWNQGSWZ384', 'fei.zhang@sina.com.cn')
53
+ s = Spear.application_status('J3H0YY6LLK553R3Z32Z', 'zhangfei@sina.com.cn')
54
54
  puts s.response
55
55
  end
56
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spear-cb-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - CBluowei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-11 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder