testcloud_devices_ruby 0.0.0.5 → 0.0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10adc55bb58e27978441a2ad206c02e13a1625a9
4
- data.tar.gz: cbc209601c26cb52172f2d58c90f2ea65dd0abb7
3
+ metadata.gz: 97d56cd8397ff4a549daa2d977cbe8a306e6b7db
4
+ data.tar.gz: 1888da4b7f79fb09ecf933bed1312229821d21c4
5
5
  SHA512:
6
- metadata.gz: 127e358a92ef23983be3ace1f5dc6ddbcb94e3faee2b44056e4a0070587dfae7b05151c92f902c98d17a43cb231a54901cd2799653cf2ddf8121a48471a15fa1
7
- data.tar.gz: 2a3d91794e6e9a4ac9a980e90151e0f8c538ff4fc35e20d27b9bc4f95c09caccc989823fb0ea9b218b0dbc5cc8841150ac83ee7029611e5995d8a8fbf2fc7cb7
6
+ metadata.gz: c24f24e09aa083a7d905f623ecc166153968e43c068ae7f79f03540c94118a012cb5474f4343a9ef9b3395ff374c4e038cae53d47d7bf1e215a2b6232c5be8a6
7
+ data.tar.gz: f7a63c03a10dc14c7ee0d6fb194b16343ec00bec24c517a27148bb120353d2fc12baa3e278595c5a2c70b3e91c69bde85b004989ab383360c8a8246c30280b40
@@ -1,68 +1,42 @@
1
- require 'forwardable'
2
1
  module Testcloud
3
2
  module Devices
4
3
  class Client
5
4
  include HTTParty
6
- extend Forwardable
5
+ include Testcloud::Devices::Resources
7
6
 
8
- DEFAULT_URL ||= 'https://stan.testcloud.io'
9
7
  API_TOKEN_KEY ||= 'X-Testcloud-Devices-Token'
10
8
 
11
9
  attr_accessor :type, :category, :api_token, :raw_response, :response
12
- def_delegators :raw_response, :ok?, :success?, :code
10
+
11
+ delegate :ok?, to: :raw_response
12
+ delegate :success?, to: :raw_response
13
+ delegate :code, to: :raw_response
14
+ delegate :config, to: 'Testcloud::Devices::Client'
13
15
 
14
16
  class << self
17
+ attr_reader :config
15
18
  def setup(&block)
16
- yield(self)
17
- end
18
-
19
- def api_token=(value)
20
- @api_token = value
21
- end
22
-
23
- def api_token
24
- @api_token
25
- end
26
-
27
- def url
28
- @url
29
- end
30
-
31
- def url=(value)
32
- @url = value
19
+ @config = Testcloud::Devices::Config.new
20
+ yield(@config)
33
21
  end
34
22
  end
35
23
 
36
24
  def initialize(options = {})
37
25
  @type, @category = options[:type], options[:category]
38
26
  self.class.debug_output if options[:debug]
39
- self.class.base_uri(options[:url] || self.class.url || DEFAULT_URL)
40
- self.class.api_token = options[:api_token] if options[:api_token]
41
- end
42
-
43
- def types
44
- @raw_response = self.class.get('/devices/types', access_headers)
45
- @response = Response.new(@raw_response).keys
46
- end
47
-
48
- def categories
49
- @raw_response = self.class.get("/devices/#{type.pluralize}/categories", access_headers)
50
- @response = Response.new(@raw_response).keys
51
- end
52
-
53
- def validate(data = {})
54
- @raw_response = self.class.post("/devices/#{type}/#{category}", access_headers.merge(body: data.to_json))
55
- @response = Response.new(@raw_response)
27
+ self.class.base_uri(options[:url] || config.url || Testcloud::Devices::Config::DEFAULT_URL)
28
+ config.api_token = options[:api_token] if options[:api_token]
56
29
  end
57
30
 
58
- def form_data
59
- @raw_response = self.class.get("/devices/#{type}/#{category}/form_data", access_headers)
60
- @response = Response.new(@raw_response)
31
+ def errors?
32
+ return true if raw_response.code >= 300
33
+ return true if response.has_key?(:errors)
34
+ false
61
35
  end
62
36
 
63
37
  private
64
38
  def access_headers
65
- @access_headers ||= { headers: { API_TOKEN_KEY => self.class.api_token, 'Content-Type' => 'application/json' } }
39
+ @access_headers ||= { headers: { API_TOKEN_KEY => config.api_token, 'Content-Type' => 'application/json' } }
66
40
  end
67
41
 
68
42
  end
@@ -0,0 +1,8 @@
1
+ module Testcloud
2
+ module Devices
3
+ class Config
4
+ DEFAULT_URL ||= 'https://stan.testcloud.io'
5
+ attr_accessor :api_token, :url
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,42 @@
1
+ module Testcloud
2
+ module Devices
3
+ module Resources
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+
8
+ # Return all available device types
9
+ def types
10
+ @raw_response = self.class.get('/devices/types', access_headers)
11
+ @response = Response.new(@raw_response).keys
12
+ end
13
+
14
+ # Return all available categories for a given device type
15
+ def categories
16
+ @raw_response = self.class.get("/devices/#{type.pluralize}/categories", access_headers)
17
+ @response = Response.new(@raw_response).keys
18
+ end
19
+
20
+ # Takes device parameters, validates them, and returns the correct device hash
21
+ # an 'errors' key is always present if anything goes wrong.
22
+ def validate(data = {})
23
+ @raw_response = self.class.post("/devices/#{type}/#{category}", access_headers.merge(body: data.to_json))
24
+ @response = Response.new(@raw_response)
25
+ end
26
+
27
+ # Get form data for a type and category (such as os, os_version, vendor, device models)
28
+ def form_data
29
+ @raw_response = self.class.get("/devices/#{type}/#{category}/form_data", access_headers)
30
+ @response = Response.new(@raw_response)
31
+ end
32
+
33
+ # Submit a device that's missing from the database
34
+ def report_missing_device(data = {})
35
+ @raw_response = self.class.post("/devices/report_missing", access_headers.merge(body: data.to_json))
36
+ @response = Response.new(@raw_response)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -10,7 +10,7 @@ module Testcloud
10
10
  MAJOR = 0
11
11
  MINOR = 0
12
12
  PATCH = 0
13
- PRE = 5
13
+ PRE = 6
14
14
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
15
15
  end
16
16
 
@@ -1,10 +1,13 @@
1
1
  require 'httparty'
2
2
  require 'hashie'
3
3
  require 'active_support/inflector'
4
+ require 'active_support/core_ext/module'
4
5
 
5
6
  module Testcloud
6
7
  module Devices
7
8
  autoload :Client, 'testcloud/devices/client'
9
+ autoload :Config, 'testcloud/devices/config'
8
10
  autoload :Response, 'testcloud/devices/response'
11
+ autoload :Resources, 'testcloud/devices/resources'
9
12
  end
10
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testcloud_devices_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.5
4
+ version: 0.0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Faucett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2014-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,8 @@ extra_rdoc_files: []
122
122
  files:
123
123
  - lib/testcloud/devices.rb
124
124
  - lib/testcloud/devices/client.rb
125
+ - lib/testcloud/devices/config.rb
126
+ - lib/testcloud/devices/resources.rb
125
127
  - lib/testcloud/devices/response.rb
126
128
  - lib/testcloud/devices/ruby.rb
127
129
  - lib/testcloud/devices/ruby/version.rb