cloud_connect 2.0.2 → 3.0.3

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.
@@ -1,21 +1,94 @@
1
1
  module CloudConnect
2
- module Fields
2
+ class Client
3
+ module Fields
3
4
 
4
- # Retrieve a list of fields.
5
- # WARNING: This method uses calls not officially supported by Mobile Devices.
6
- #
7
- # @return [[Hashie::Mash]] Array of Fields
8
- def fields(reload = false)
9
- return @fields if @fields && !reload
10
- page = 1
11
- limit = 100
12
- fields = []
13
- while (slice = connection.get(connection.build_url("fields", :per_page => limit, :page => page)).body).size > 0
14
- page += 1
15
- fields += slice.map!{|hash| hash.values.first} if slice.size > 0
16
- slice.size < limit ? break : sleep(1)
5
+ # Get a field
6
+ #
7
+ # @param name [String] Name of the field
8
+ # @return [Field] The field you requested, if it exists
9
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-fields
10
+ # @example Get field 0123456789012345
11
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
12
+ # @client.field("0123456789012345")
13
+ def field(name, options={})
14
+ enhance( get("fields/#{name}", options), with: FieldMethods )
15
+ end
16
+
17
+ # Search fields
18
+ #
19
+ # @param search_term [String] The term to search for
20
+ # @return [Array] A list of fields matching the search term
21
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-fields
22
+ # @example Search for 'TEMPERATURE' in the fields
23
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
24
+ # @client.search_fields
25
+ def search_fields(search_term, options={})
26
+ enhance( get("fields?q=#{search_term}", options), with: FieldMethods )
27
+ end
28
+
29
+ # Get fields
30
+ #
31
+ # @return [Array] A list of all fields
32
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-fields
33
+ # @example List all fields
34
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
35
+ # @client.fields
36
+ def fields(options={})
37
+ enhance( get("fields", options), with: FieldMethods )
38
+ end
39
+ alias :list_fields :fields
40
+
41
+ # Create a field
42
+ #
43
+ # @param name [String] Name of the field
44
+ # @param options [Hash] A customizable set of options
45
+ # @options options [Integer] :field ID of the field
46
+ # @options options [String] :field_type Type of the field: <tt>unknown</tt>, <tt>boolean</tt>, <tt>integer</tt>, <tt>decimal</tt>, <tt>string</tt>, or <tt>base64</tt>
47
+ # @options options [String] :size Size of the field
48
+ # @options options [String] :ack
49
+ # @options options [String] :description Description of the field
50
+ # @return [Field] Your newly created field
51
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-fields#create_a_new_field
52
+ # @example Create a new Field
53
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
54
+ # @client.create_field("CUSTOM_SENSOR_TEMP", :field_type => 'integer', :size => 1, :description => "Custom sensor temp in Celsius")
55
+ def create_field(name, options={})
56
+ enhance( post("fields", options.merge({:name => name})), with: FieldMethods )
57
+ end
58
+
59
+ # Update an field
60
+ #
61
+ # @param name [String] Name of the field
62
+ # @param options [Hash] A customizable set of options
63
+ # @options options [Integer] :field ID of the field
64
+ # @options options [String] :field_type Type of the field: <tt>unknown</tt>, <tt>boolean</tt>, <tt>integer</tt>, <tt>decimal</tt>, <tt>string</tt>, or <tt>base64</tt>
65
+ # @options options [String] :size Size of the field
66
+ # @options options [String] :ack
67
+ # @options options [String] :description Description of the field
68
+ # @return [Field] Your newly updated field
69
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-fields#update_a_field
70
+ # @example Update a Field
71
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
72
+ # @client.update_field("CUSTOM_SENSOR_TEMP", :field_type => 'integer', :size => 1, :description => "Custom sensor temp in Celsius")
73
+ def update_field(name, options={})
74
+ enhance( put("/fields/#{name}", options.merge({:name => name})), with: FieldMethods )
75
+ end
76
+
77
+ # Delete a single field
78
+ #
79
+ # @param name [String] Name fo the field
80
+ # @return [Response] A response object with status
81
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-fields#delete_a_field
82
+ # @example Delete the CUSTOM_SENSOR_TEMP field
83
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
84
+ # @client.delete_field("CUSTOM_SENSOR_TEMP")
85
+ def delete_field(name, options={})
86
+ delete("fields/#{name}", options, true)
87
+ end
88
+
89
+ module FieldMethods
90
+ extend CustomMethods
17
91
  end
18
- @fields = fields.sort_by(&:id)
19
92
  end
20
93
  end
21
94
  end
@@ -1,56 +1,68 @@
1
1
  module CloudConnect
2
- module Messages
2
+ class Client
3
+ module Messages
4
+ # Get a message
5
+ #
6
+ # @param id [String] ID of the message
7
+ # @return [Message] The message you requested, if it exists
8
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0005-messages
9
+ # @example Get message 380342888036303061
10
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
11
+ # @client.message("380342888036303061")
12
+ def message(id, options={})
13
+ enhance( get("messages/#{id}", options), with: MessageMethods )
14
+ end
3
15
 
4
- require 'open-uri'
16
+ # Search messages
17
+ #
18
+ # @param search_term [String] The term to search for
19
+ # @return [Array] A list of messages matching the search term
20
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0005-messages
21
+ # @example Search for '123' in the messages
22
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
23
+ # @client.search_messages
24
+ def search_messages(search_term, options={})
25
+ enhance( get("messages?q=#{search_term}", options), with: MessageMethods )
26
+ end
5
27
 
6
- # Returns all messages that match parameters provided in +opts+ list
7
- # (if +opts+ is provided)
8
- #
9
- # @param [Hash] opts the options to filter the messages.
10
- # @option opts [String] :ret ('id, time') Select attributes to fetch
11
- # @option opts [String] :channelids List of channel ids
12
- # @option opts [String] :messageids List of message ids
13
- # @option opts [String] :unitids List of unit ids
14
- # @option opts [String] :userids List of user ids
15
- # @option opts [String] :status Message status
16
- # (0 (new), 1 (sent), 2 (received), 3 (failed))
17
- # @option opts [String] :timedout (false) Include timed-out messages
18
- # @option opts [String] :from Minimum date
19
- # @option opts [String] :to Maximum date
20
- # @option opts [String] :direction Message direction
21
- # (unittouser or usertounit)
22
- # @option opts [String] :replyto List of reference message ids
23
- # @option opts [Integer] :id_min Minimum ID
24
- # @option opts [Integer] :id_max Maximum ID
25
- # @option opts [Integer] :limit (25) Number of elements to fetch
26
- # @return [Array<Hashie::Mash>] Messages
27
- # @see http://develop.g8teway.com/p/messages.html#listing_messages
28
- def messages(opts = {})
29
- messages = connection.get(connection.build_url("messages", opts)).body
30
- messages.map!{|hash| hash.values.first}
31
- end
28
+ # Get messages from an asset
29
+ #
30
+ # @param imei [String] IMEI of the asset
31
+ # @return [Array] The messages you requested, if it exists
32
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0005-messages
33
+ # @example Get messages from the asset 351732050019192
34
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
35
+ # @client.asset_messages("351732050019192")
36
+ def asset_messages(imei, options={})
37
+ enhance( get("assets/#{imei}/messages", options), with: MessageMethods )
38
+ end
39
+
40
+ # Get all messages
41
+ #
42
+ # @return [Array] A list of all messages
43
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0005-messages
44
+ # @example List all messages
45
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
46
+ # @client.messages
47
+ def messages(options={})
48
+ enhance( get("messages", options), with: MessageMethods )
49
+ end
50
+ alias :list_messages :messages
51
+
52
+ # Send a message to the unit
53
+ #
54
+ # @param imei [String] IMEI of the asset
55
+ # @param channel [String] Channel for the message
56
+ # @param payload [String] Payload of the message to send
57
+ # @return [Message] The message
58
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0005-messages#push_a_message_to_an_asset
59
+ def send_message(imei, channel, payload, options={})
60
+ enhance( post("messages", options.merge({recipient: imei, asset: imei, channel: channel, b64_payload: Base64.encode64(payload)})), with: MessageMethods )
61
+ end
32
62
 
33
- # Send a message to a specific device
34
- #
35
- # @param [Integer] unit
36
- # @param [Integer] channel
37
- # @param [String] content
38
- # @param [Hash] opts
39
- # @return [Hashie::Mash] The message
40
- # @see http://develop.g8teway.com/p/messages.html#sending_a_new_message
41
- def send_message(unit, channel, content, opts = {})
42
- # TODO: rename #message_create ?
43
- opts.merge! :channelid => channel, :unitid => unit, :content => content
44
- response = connection.post do |req|
45
- if version == "v1.5"
46
- req.url 'ws?messagesend'
47
- req.body = "unit=#{unit}&channel=#{channel}&content=#{URI::encode(content)}"
48
- else
49
- req.url 'messages'
50
- req.body = {:message => opts}
51
- end
63
+ module MessageMethods
64
+ extend CustomMethods
52
65
  end
53
- response.body.values.first
54
66
  end
55
67
  end
56
68
  end
@@ -0,0 +1,46 @@
1
+ module CloudConnect
2
+ class Client
3
+ module Tracks
4
+
5
+ # Get a track
6
+ #
7
+ # @param id [String] ID of the track
8
+ # @return [Track] The track you requested, if it existsle ||
9
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0004-tracks
10
+ # @example Get track 0123456789012345
11
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
12
+ # @client.track("0123456789012345")
13
+ def track(id, options={})
14
+ enhance( get("tracks/#{id}", options), with: TrackMethods )
15
+ end
16
+
17
+ # Search tracks
18
+ #
19
+ # @param search_term [String] The term to search for
20
+ # @return [Array] A list of tracks matching the search term
21
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0004-tracks
22
+ # @example Search for '123' in the tracks
23
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
24
+ # @client.search_tracks
25
+ def search_tracks(search_term, options={})
26
+ enhance( get("tracks?q=#{search_term}", options), with: TrackMethods )
27
+ end
28
+
29
+ # Get tracks
30
+ #
31
+ # @return [Array] A list of all tracks
32
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0004-messages
33
+ # @example List all tracks
34
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
35
+ # @client.tracks
36
+ def tracks(options={})
37
+ enhance( get("tracks", options), with: TrackMethods )
38
+ end
39
+
40
+ alias :list_tracks :tracks
41
+ module TrackMethods
42
+ extend CustomMethods
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,66 +1,52 @@
1
+ require 'cloud_connect/authentication'
2
+ require 'cloud_connect/connection'
3
+ require 'cloud_connect/request'
4
+
5
+ require 'cloud_connect/client/custom_methods'
6
+ require 'cloud_connect/client/assets'
7
+ require 'cloud_connect/client/configurations'
8
+ require 'cloud_connect/client/fields'
9
+ require 'cloud_connect/client/channels'
10
+ require 'cloud_connect/client/tracks'
11
+ require 'cloud_connect/client/messages'
12
+
1
13
  module CloudConnect
2
14
  class Client
3
- attr_reader :username, :password, :account, :env, :cookie, :version
4
- attr_writer :cookie
15
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
5
16
 
6
17
  def initialize(options={})
7
- @username = options[:username] || CloudConnect.username
8
- @password = options[:password] || CloudConnect.password
9
- @account = options[:account] || CloudConnect.account
10
- @env = options[:env] || CloudConnect.env || "prod"
11
- @version = options[:version] || "v2"
12
- end
13
-
14
- # Raw HTTP connection, either Faraday::Connection
15
- #
16
- # @return [Faraday::Connection]
17
- def connection
18
- params = {}
19
- params[:access_token] = @access_token if @access_token
20
- @connection ||= Faraday::Connection.new(:url => api_url, :params => params, :headers => default_headers) do |builder|
21
- builder.use Faraday::Request::CookieAuth, self
22
- builder.adapter Faraday.default_adapter
23
- builder.use Faraday::Response::RaiseHttp5xx
24
- builder.use Faraday::Response::ParseJson
25
- builder.use Faraday::Response::RaiseHttp4xx
26
- builder.use Faraday::Response::Mashify
27
- #builder.response :yajl # Faraday::Request::Yajl
28
- end
29
- end
30
-
31
- # Provides the URL for accessing the API
32
- #
33
- # @return [String]
34
- def api_url
35
- if env == "preprod"
36
- "http://srv/api/v2"
37
- else
38
- "http://#{env}.g8teway.com/api/#{version}"
18
+ options = CloudConnect.options.merge(options)
19
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
20
+ send("#{key}=", options[key])
39
21
  end
40
22
  end
41
23
 
42
- def login
43
- if version == "v1.5"
44
- req = connection.post('ws?login', "username=#{username}&password=#{password}&client=#{account}")
45
- else
46
- req = connection.post('sessions', {:login => username, :password => password, :client => account})
24
+ def enhance(object, with_opts)
25
+ # @private
26
+ # Add custom methods to provided object(s).
27
+ # This method provides syntaxic suggar upon <tt>Module.apply_to(object)</tt>,
28
+ # allowing you to write <tt>enhance object, with: Module</tt>
29
+ #
30
+ # @param object [Object] An Object or Array of Objects to enhance.
31
+ # @param with_opts [Hash] Customizable set of options.
32
+ # @options with_opts [Module] :with Module to include.
33
+ # @return [Object] Enhanced initial object.
34
+ # @example Enhance an instance of Hashie::Mash with methods defined in the AssetMethods module
35
+ # enhance( Hashie::Mash.new, :with => AssetMethods)
36
+ object.tap do |obj|
37
+ with_opts[:with].apply_to(obj, client: self)
47
38
  end
48
39
  end
49
40
 
50
- private
51
- # @private
52
- def default_headers
53
- headers = {
54
- :accept => 'application/json',
55
- :user_agent => 'CloudClient Ruby gem'
56
- }
57
- end
41
+ include CloudConnect::Authentication
42
+ include CloudConnect::Connection
43
+ include CloudConnect::Request
58
44
 
59
- include Units
60
- include Users
61
- include Channels
62
- include Messages
63
- include Fields
64
- include Trackings
45
+ include CloudConnect::Client::Assets
46
+ include CloudConnect::Client::Configurations
47
+ include CloudConnect::Client::Fields
48
+ include CloudConnect::Client::Channels
49
+ include CloudConnect::Client::Tracks
50
+ include CloudConnect::Client::Messages
65
51
  end
66
52
  end
@@ -0,0 +1,60 @@
1
+ require 'faraday'
2
+ require 'cloud_connect/version'
3
+
4
+ module CloudConnect
5
+ module Configuration
6
+ VALID_OPTIONS_KEYS = [
7
+ :adapter,
8
+ :faraday_config_block,
9
+ :api_version,
10
+ :api_url,
11
+ :api_path,
12
+ :account,
13
+ :token,
14
+ :proxy,
15
+ :request_host,
16
+ :user_agent,
17
+ :auto_traversal,
18
+ :per_page,
19
+ ].freeze
20
+
21
+ API_VERSION = 3
22
+
23
+ DEFAULT_ADAPTER = Faraday.default_adapter
24
+ DEFAULT_API_URL = "cloudconnect.io"
25
+ API_PATH = "/api/v#{API_VERSION}/"
26
+ DEFAULT_USER_AGENT = "CloudConnect Ruby Gem #{CloudConnect::VERSION}".freeze
27
+ DEFAULT_AUTO_TRAVERSAL = false
28
+
29
+ attr_accessor(*VALID_OPTIONS_KEYS)
30
+
31
+ def self.extended(base)
32
+ base.reset
33
+ end
34
+
35
+ def configure
36
+ yield self
37
+ end
38
+
39
+ def options
40
+ VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
41
+ end
42
+
43
+ def faraday_config(&block)
44
+ @faraday_config_block = block
45
+ end
46
+
47
+ def reset
48
+ self.adapter = DEFAULT_ADAPTER
49
+ self.api_version = API_VERSION
50
+ self.api_url = DEFAULT_API_URL
51
+ self.api_path = API_PATH
52
+ self.account = nil
53
+ self.token = nil
54
+ self.proxy = nil
55
+ self.request_host = nil
56
+ self.user_agent = DEFAULT_USER_AGENT
57
+ self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,49 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/response/raise_cloud_connect_error'
3
+
4
+ module CloudConnect
5
+ # @private
6
+ module Connection
7
+ private
8
+
9
+ def api_endpoint
10
+ File.join(@api_url, @api_path, "")
11
+ end
12
+
13
+ def url
14
+ url = "http://#{[account, api_endpoint].join('.')}"
15
+ end
16
+
17
+ def connection(raw=false, force_urlencoded=false)
18
+ options = {
19
+ :ssl => { :verify => false },
20
+ :url => url,
21
+ }
22
+
23
+ options[:proxy] = proxy unless proxy.nil?
24
+
25
+ # TODO: Don't build on every request
26
+ connection = Faraday.new(options) do |builder|
27
+ if !force_urlencoded
28
+ builder.request :json
29
+ else
30
+ builder.request :url_encoded
31
+ end
32
+
33
+ builder.use Faraday::Response::RaiseCloudConnectError
34
+
35
+ unless raw
36
+ builder.use FaradayMiddleware::Mashify
37
+ builder.use FaradayMiddleware::ParseJson
38
+ end
39
+
40
+ faraday_config_block.call(builder) if faraday_config_block
41
+
42
+ builder.adapter *adapter
43
+ end
44
+
45
+ connection.basic_auth authentication[:token], 'X'
46
+ connection
47
+ end
48
+ end
49
+ end
@@ -1,12 +1,34 @@
1
1
  module CloudConnect
2
+ # Custom error class for rescuing from all CloudConnect errors
2
3
  class Error < StandardError; end
3
- class BadGateway < Error; end
4
+
5
+ # Raised when CloudConnect returns a 400 HTTP status code
4
6
  class BadRequest < Error; end
7
+
8
+ # Raised when CloudConnect returns a 401 HTTP status code
9
+ class Unauthorized < Error; end
10
+
11
+ # Raised when CloudConnect returns a 403 HTTP status code
5
12
  class Forbidden < Error; end
6
- class InternalServerError < Error; end
7
- class NotAcceptable < Error; end
13
+
14
+ # Raised when CloudConnect returns a 404 HTTP status code
8
15
  class NotFound < Error; end
9
- class ServiceUnavailable < Error; end
16
+
17
+ # Raised when CloudConnect returns a 406 HTTP status code
18
+ class NotAcceptable < Error; end
19
+
20
+ # Raised when CloudConnect returns a 422 HTTP status code
10
21
  class UnprocessableEntity < Error; end
11
- class Unauthorized < Error; end
22
+
23
+ # Raised when CloudConnect returns a 500 HTTP status code
24
+ class InternalServerError < Error; end
25
+
26
+ # Raised when CloudConnect returns a 501 HTTP status code
27
+ class NotImplemented < Error; end
28
+
29
+ # Raised when CloudConnect returns a 502 HTTP status code
30
+ class BadGateway < Error; end
31
+
32
+ # Raised when CloudConnect returns a 503 HTTP status code
33
+ class ServiceUnavailable < Error; end
12
34
  end
@@ -0,0 +1,78 @@
1
+ require 'json'
2
+ require 'base64'
3
+ require 'faraday_middleware'
4
+ require 'faraday/response/raise_cloud_connect_error'
5
+
6
+ module CloudConnect
7
+ class Notification
8
+ module Notification
9
+
10
+ # Notification
11
+ #
12
+ # @param json [String] JSON of the POST request
13
+ # @return [Array] The fields from the json, deserialized and decoded
14
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0013-notifications
15
+ # @example Notification
16
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
17
+ # @client.notification(json)
18
+ def notification(json)
19
+ result = connection(false, false)
20
+ json = JSON.parse(json)
21
+ if json.class == [].class
22
+ mash = []
23
+ json.each do |obj|
24
+ mash << Hashie::Mash.new(obj)
25
+ end
26
+ else
27
+ mash = Hashie::Mash.new(json)
28
+ end
29
+ return parse_notification(mash)
30
+ end
31
+
32
+ alias :list_notification :notification
33
+
34
+ module NotificationMethods
35
+ extend CustomMethods
36
+ end
37
+
38
+ private
39
+
40
+ def decode_b64(b64, type)
41
+ if type == "string"
42
+ return Base64.decode64(b64)
43
+ elsif type == "integer"
44
+ decoded_value = 0
45
+ bytes = Base64.decode64(b64).bytes
46
+ for byte in bytes
47
+ decoded_value <<= 8
48
+ decoded_value += byte
49
+ end
50
+ decoded_value
51
+ return decoded_value
52
+ end
53
+ end
54
+
55
+ def decode_notification(mash)
56
+ if mash.meta.event == "message"
57
+ mash.payload.payload = decode_b64(mash.payload.b64_payload, "string")
58
+ elsif mash.meta.event == "track"
59
+ mash.payload.fields.each do |attr|
60
+ attr.last.b64_value = decode_b64(attr.last.b64_value, "integer")
61
+ end
62
+ end
63
+ return mash
64
+ end
65
+
66
+ def parse_notification(mashes)
67
+ if mashes.class == [].class
68
+ mashes.each do |mash|
69
+ mash = parse_notification(mash)
70
+ end
71
+ return mashes
72
+ else
73
+ return decode_notification(mashes)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,43 @@
1
+ require 'cloud_connect/authentication'
2
+ require 'cloud_connect/connection'
3
+ require 'cloud_connect/request'
4
+
5
+ require 'cloud_connect/client/custom_methods'
6
+ require 'cloud_connect/notification/notification'
7
+
8
+ module CloudConnect
9
+ class Notification
10
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
11
+
12
+ def initialize(options={})
13
+ options = CloudConnect.options.merge(options)
14
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ def enhance(object, with_opts)
20
+ # @private
21
+ # Add custom methods to provided object(s).
22
+ # This method provides syntaxic suggar upon <tt>Module.apply_to(object)</tt>,
23
+ # allowing you to write <tt>enhance object, with: Module</tt>
24
+ #
25
+ # @param object [Object] An Object or Array of Objects to enhance.
26
+ # @param with_opts [Hash] Customizable set of options.
27
+ # @options with_opts [Module] :with Module to include.
28
+ # @return [Object] Enhanced initial object.
29
+ # @example Enhance an instance of Hashie::Mash with methods defined in the AssetMethods module
30
+ # enhance( Hashie::Mash.new, :with => AssetMethods)
31
+ object.tap do |obj|
32
+ with_opts[:with].apply_to(obj, client: self)
33
+ end
34
+ end
35
+
36
+ include CloudConnect::Authentication
37
+ include CloudConnect::Connection
38
+ include CloudConnect::Request
39
+
40
+ include CloudConnect::Notification::Notification
41
+
42
+ end
43
+ end