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.
data/.gitignore CHANGED
@@ -1,6 +1,23 @@
1
- pkg/*
2
1
  *.gem
2
+ *.rbc
3
+ *.swp
4
+ *.tmproj
5
+ *~
6
+ .\#*
3
7
  .bundle
8
+ .config
4
9
  .yardoc
5
- .DS_Store
6
- doc/*
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ \#*
13
+ _yardoc
14
+ coverage
15
+ doc/
16
+ lib/bundler/man
17
+ pkg
18
+ rdoc
19
+ spec/reports
20
+ test/tmp
21
+ test/version_tmp
22
+ tmp
23
+ tmtags
data/Gemfile CHANGED
@@ -1,2 +1,3 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
+
2
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,46 +1,57 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloud_connect (2.0.0)
5
- faraday (~> 0.8.0)
6
- faraday_middleware (~> 0.8.0)
7
- hashie (~> 1.2.0)
8
- json (~> 1.8.0)
9
- multi_json (~> 1.10.0)
4
+ cloud_connect (3.0.0)
5
+ addressable (~> 2.2)
6
+ faraday (~> 0.8)
7
+ faraday_middleware (~> 0.8)
8
+ hashie (~> 1.2)
9
+ multi_json
10
10
 
11
11
  GEM
12
- remote: http://rubygems.org/
12
+ remote: https://rubygems.org/
13
13
  specs:
14
- bluecloth (2.2.0)
15
- diff-lcs (1.2.5)
16
- faraday (0.8.9)
17
- multipart-post (~> 1.2.0)
18
- faraday_middleware (0.8.8)
14
+ addressable (2.3.2)
15
+ crack (0.3.1)
16
+ diff-lcs (1.1.3)
17
+ faraday (0.8.4)
18
+ multipart-post (~> 1.1)
19
+ faraday_middleware (0.9.0)
19
20
  faraday (>= 0.7.4, < 0.9)
20
21
  hashie (1.2.0)
21
- json (1.8.1)
22
- multi_json (1.10.1)
23
- multipart-post (1.2.0)
24
- rake (0.9.6)
25
- rspec (3.0.0)
26
- rspec-core (~> 3.0.0)
27
- rspec-expectations (~> 3.0.0)
28
- rspec-mocks (~> 3.0.0)
29
- rspec-core (3.0.3)
30
- rspec-support (~> 3.0.0)
31
- rspec-expectations (3.0.3)
32
- diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.0.0)
34
- rspec-mocks (3.0.3)
35
- rspec-support (~> 3.0.0)
36
- rspec-support (3.0.3)
22
+ json (1.7.5)
23
+ maruku (0.6.1)
24
+ syntax (>= 1.0.0)
25
+ multi_json (1.3.7)
26
+ multipart-post (1.1.5)
27
+ rake (10.0.2)
28
+ rspec (2.12.0)
29
+ rspec-core (~> 2.12.0)
30
+ rspec-expectations (~> 2.12.0)
31
+ rspec-mocks (~> 2.12.0)
32
+ rspec-core (2.12.0)
33
+ rspec-expectations (2.12.0)
34
+ diff-lcs (~> 1.1.3)
35
+ rspec-mocks (2.12.0)
36
+ simplecov (0.7.1)
37
+ multi_json (~> 1.0)
38
+ simplecov-html (~> 0.7.1)
39
+ simplecov-html (0.7.1)
40
+ syntax (1.0.0)
41
+ webmock (1.9.0)
42
+ addressable (>= 2.2.7)
43
+ crack (>= 0.1.7)
44
+ yard (0.8.3)
37
45
 
38
46
  PLATFORMS
39
47
  ruby
40
48
 
41
49
  DEPENDENCIES
42
- bluecloth (>= 2.0)
43
- bundler (>= 1.0.0)
44
50
  cloud_connect!
45
- rake (~> 0.8)
51
+ json (~> 1.7)
52
+ maruku
53
+ rake
46
54
  rspec
55
+ simplecov
56
+ webmock
57
+ yard
data/README.md CHANGED
@@ -1,97 +1,42 @@
1
- The Coud Connect Ruby Gem
2
- ==========================
1
+ # CloudConnect
2
+ Simple Ruby wrapper for the CloudConnect v3 API.
3
3
 
4
- A Ruby wrapper for the [Cloud Connect API](http://develop.g8teway.com).
4
+ ## Installation
5
5
 
6
- Installation
7
- ------------
8
- gem install cloud_connect
6
+ ```bash
7
+ gem install cloud_connect
8
+ ```
9
9
 
10
- Usage
11
- -----
10
+ ## Documentation
12
11
 
13
- require 'rubygems'
14
- require 'cloud_connect'
12
+ http://rdoc.info/gems/cloud_connect
15
13
 
16
- ### Instantiate a client
14
+ ## Authenticated Requests
17
15
 
18
- cloud_connect = CloudConnect::Client.new(:username => 'user', :password => 'password', :account => 'test', :env => 'sandbox')
16
+ ### Setup a client with your token
19
17
 
20
- ### Or configure once
18
+ ```ruby
19
+ cc = CloudConnect::Client.new(:account => "demo", :token => "token")
20
+ cc.asset("imei")
21
+ ```
21
22
 
22
- CloudConnect.configure do |config|
23
- config.username = 'user'
24
- config.password = 'password'
25
- config.account = 'test'
26
- config.env = 'sandbox'
27
- end
28
- cloud_connect = CloudConnect.client.new
23
+ ## Examples
29
24
 
30
- ### Login
25
+ ### Show an asset
31
26
 
32
- cloud_connect.login
27
+ ```ruby
28
+ cc.asset("imei")
29
+ => #<Hashie::Mash imei="imei" name=nil serial=nil url="http://url.cloudconnect.io/api/v3/assets/imei">
30
+ ```
33
31
 
34
- ### Examples
32
+ ### Show last messages for an asset
35
33
 
36
- cloud_connect.units
37
- => [<#Hashie::Mash id=2 lat=nil lng=nil time=nil>, <#Hashie::Mash id=3 lat=4884481 lng=226392 time="2009-07-08T10:23:13Z">]
34
+ ```ruby
35
+ cc.messages(asset:"imei")
36
+ ```
38
37
 
39
- Details for the current user
40
- cloud_connect.user
38
+ ### Channels
41
39
 
42
- Details for another user
43
-
44
- cloud_connect.user('other_user')
45
- cloud_connect.user(1)
46
-
47
- Send a message to a unit
48
-
49
- cloud_connect.send_message(1, 11, "Hello World!")
50
-
51
- Get a unit's last known position
52
-
53
- unit = cloud_connect.unit(3)
54
- puts "#{unit.location.join(', ')} @ #{unit.time}"
55
-
56
- We recommand you install the [yajl-ruby](http://github.com/brianmario/yajl-ruby) Gem
57
- for improved performance over the default pure ruby JSON library.
58
-
59
- Contributing
60
- ------------
61
- In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
62
-
63
- Here are some ways *you* can contribute:
64
-
65
- * by using alpha, beta, and prerelease versions
66
- * by reporting bugs
67
- * by suggesting new features
68
- * by writing or editing documentation
69
- * by writing specifications
70
- * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
71
- * by refactoring code
72
- * by closing [issues](http://github.com/mobile-devices/cloud_connect/issues)
73
- * by reviewing patches
74
-
75
- All contributors will be added to the [HISTORY](https://github.com/mobile-devices/cloud_connect/blob/master/HISTORY.md)
76
- file and will receive the respect and gratitude of the community.
77
-
78
- Submitting an Issue
79
- -------------------
80
- We use the [GitHub issue tracker](http://github.com/mobile-devices/cloud_connect/issues) to track bugs and
81
- features. Before submitting a bug report or feature request, check to make sure it hasn't already
82
- been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
83
- bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
84
- details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
85
- operating system. Ideally, a bug report should include a pull request with failing specs.
86
-
87
- Submitting a Pull Request
88
- -------------------------
89
- 1. Fork the project.
90
- 2. Create a topic branch.
91
- 3. Implement your feature or bug fix.
92
- 4. Add documentation for your feature or bug fix.
93
- 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
94
- 6. Add specs for your feature or bug fix.
95
- 7. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
96
- 8. Commit and push your changes.
97
- 9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
40
+ ```
41
+ cc.channels
42
+ ```
data/Rakefile CHANGED
@@ -1,47 +1,19 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
4
10
  namespace :doc do
5
11
  require 'yard'
6
12
  YARD::Rake::YardocTask.new do |task|
7
- task.files = ['lib/cloud_connect.rb', 'lib/cloud_connect/**/*.rb']
13
+ task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb']
8
14
  task.options = [
9
- '--protected',
10
15
  '--output-dir', 'doc/yard',
11
- '--tag', 'format:Supported formats',
12
- '--tag', 'authenticated:Requires Authentication',
13
- '--tag', 'rate_limited:Rate Limited',
14
16
  '--markup', 'markdown',
15
17
  ]
16
18
  end
17
19
  end
18
-
19
- task :irb do
20
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
21
- require 'irb'
22
- require 'bundler/setup'
23
- require 'cloud_connect'
24
- module IRB # :nodoc:
25
- def self.start_session(binding)
26
- unless @__initialized
27
- args = ARGV
28
- ARGV.replace(ARGV.dup)
29
- IRB.setup(nil)
30
- ARGV.replace(args)
31
- @__initialized = true
32
- end
33
-
34
- ws = WorkSpace.new(binding)
35
- irb = Irb.new(ws)
36
-
37
- @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
38
- @CONF[:MAIN_CONTEXT] = irb.context
39
-
40
- catch(:IRB_EXIT) do
41
- irb.eval_input
42
- end
43
- end
44
-
45
- IRB.start_session(binding)
46
- end
47
- end
@@ -1,31 +1,30 @@
1
- require File.expand_path("../lib/cloud_connect/version", __FILE__)
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/cloud_connect/version', __FILE__)
2
3
 
3
- Gem::Specification.new do |s|
4
- s.name = "cloud_connect"
5
- s.version = CloudConnect::VERSION
6
- s.platform = Gem::Platform::RUBY
7
- s.authors = ["Jean-Paul Bonnetouche"]
8
- s.email = ["alexandre.mora@mobile-devices.fr"]
9
- s.homepage = "http://rubygems.org/gems/cloud_connect"
10
- s.summary = "Wrapper for Cloud Connect"
11
- s.description = "Ruby Wrapper for the Mobile Devices Cloud Connect API"
12
- s.version = '2.0.2'
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'addressable', '~> 2.2'
6
+ gem.add_dependency 'faraday', '~> 0.8'
7
+ gem.add_dependency 'faraday_middleware', '~> 0.8'
8
+ gem.add_dependency 'hashie', '~> 1.2'
9
+ gem.add_dependency 'multi_json'
10
+ gem.add_development_dependency 'json', '~> 1.7'
11
+ gem.add_development_dependency 'maruku'
12
+ gem.add_development_dependency 'rake'
13
+ gem.add_development_dependency 'rspec'
14
+ gem.add_development_dependency 'simplecov'
15
+ gem.add_development_dependency 'webmock'
16
+ gem.add_development_dependency 'yard'
17
+ gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
13
18
 
14
- s.required_rubygems_version = ">= 1.3.6"
15
-
16
- s.add_runtime_dependency "json", "~> 1.8.0"
17
- s.add_runtime_dependency "multi_json", "~> 1.10.0"
18
- s.add_runtime_dependency "faraday", "~> 0.8.0"
19
- s.add_runtime_dependency "faraday_middleware", "~> 0.8.0"
20
- s.add_runtime_dependency "hashie", "~> 1.2.0"
21
-
22
- s.add_development_dependency "bundler", ">= 1.0.0"
23
- s.add_development_dependency "bluecloth", ">= 2.0"
24
- s.add_development_dependency "rake", "~> 0.8"
25
- #s.add_development_dependency "yard", "~> 0.6"
26
- s.add_development_dependency "rspec"
27
-
28
- s.files = `git ls-files`.split("\n")
29
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
30
- s.require_path = 'lib'
19
+ gem.authors = ['Jean-Paul Bonnetouche']
20
+ gem.summary = 'Wrapper for the CloudConnect v3 API'
21
+ gem.description = 'Simple wrapper for the CloudConnect v3 API'
22
+ gem.email = ['jean-paul.bonnetouche@mobile-devices.fr']
23
+ gem.files = `git ls-files`.split("\n")
24
+ gem.homepage = 'https://github.com/mobile-devices/cloud_connect'
25
+ gem.name = 'cloud_connect'
26
+ gem.platform = Gem::Platform::RUBY
27
+ gem.require_paths = ['lib']
28
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
+ gem.version = CloudConnect::VERSION
31
30
  end
@@ -0,0 +1,15 @@
1
+ module CloudConnect
2
+ module Authentication
3
+ def authentication
4
+ if token
5
+ {:token => token}
6
+ else
7
+ {}
8
+ end
9
+ end
10
+
11
+ def authenticated?
12
+ !authentication.empty?
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,102 @@
1
+ module CloudConnect
2
+ class Client
3
+ module Assets
4
+ # Get an asset
5
+ #
6
+ # @param imei [String] IMEI of the asset
7
+ # @return [Asset] The asset you requested, if it exists
8
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0003-assets
9
+ # @example Get asset 0123456789012345
10
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
11
+ # @client.asset("0123456789012345")
12
+ def asset(imei, options={})
13
+ enhance( get("assets/#{imei}", options), with: AssetMethods )
14
+ end
15
+
16
+ # Search assets
17
+ #
18
+ # @param search_term [String] The term to search for
19
+ # @return [Array] A list of assets matching the search term
20
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0003-assets
21
+ # @example Search for '123' in the assets
22
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
23
+ # @client.search_assets
24
+ def search_assets(search_term, options={})
25
+ enhance( get("assets?q=#{search_term}", options), with: AssetMethods )
26
+ end
27
+
28
+ # Get assets
29
+ #
30
+ # @return [Array] A list of all assets
31
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0003-assets
32
+ # @example List all assets
33
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
34
+ # @client.list_assets
35
+ def assets(options={})
36
+ enhance( get("assets", options), with: AssetMethods )
37
+ end
38
+ alias :list_assets :assets
39
+
40
+ # Create an asset
41
+ #
42
+ # @param imei [String] IMEI of the asset
43
+ # @param options [Hash] A customizable set of options
44
+ # @options options [String] :name Name of the asset
45
+ # @options options [String] :serial Serial number of the asset
46
+ # @options options [String] :description Description of the asset
47
+ # @return [Asset] Your newly created asset
48
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0003-assets#create_a_new_asset
49
+ # @example Create a new Asset
50
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
51
+ # @client.create_asset("359551033822346", :name => 'General Lee', :serial => "50030000005322", :description => "The Dukes of Hazzard")
52
+ def create_asset(imei, options={})
53
+ enhance( post("assets", options.merge({:imei => imei})), with: AssetMethods )
54
+ end
55
+
56
+ # Update an asset
57
+ #
58
+ # @param imei [String] IMEI of the asset
59
+ # @param options [Hash] A customizable set of options
60
+ # @options options [String] :name Name of the asset
61
+ # @options options [String] :serial Serial number of the asset
62
+ # @options options [String] :description Description of the asset
63
+ # @return [Asset] Your newly updated asset
64
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0003-assets#update_an_asset
65
+ # @example Update an Asset
66
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
67
+ # @client.update_asset("359551033822346", :name => 'General Lee', :serial => "50030000005322", :description => "The Dukes of Hazzard")
68
+ def update_asset(imei, options={})
69
+ enhance( put("assets/#{imei}", options.merge({:imei => imei})), with: AssetMethods )
70
+ end
71
+
72
+ # Delete a single asset
73
+ #
74
+ # @param imei [String] IMEI fo the field
75
+ # @return [Response] A response object with status
76
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0003-assets#delete_an_asset
77
+ # @example Delete the "359551033822346" asset
78
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
79
+ # @client.delete_asset("359551033822346")
80
+ def delete_asset(imei, options={})
81
+ delete("assets/#{imei}", options, true)
82
+ end
83
+
84
+ module AssetMethods
85
+ extend CustomMethods
86
+ # Send a message to the unit
87
+ #
88
+ # @param channel [String] Channel for the message
89
+ # @param payload [String] Payload of the message to send
90
+ # @return [Message] The message
91
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0005-messages#push_a_message_to_an_asset
92
+ def send_message(channel, payload, opts = {})
93
+ _client.send_message(imei, channel, payload, opts)
94
+ end
95
+
96
+ def messages(opts = {})
97
+ _client.messages(opts.merge asset: imei)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,22 +1,89 @@
1
1
  module CloudConnect
2
- module Channels
2
+ class Client
3
+ module Channels
4
+ # Get a channel
5
+ #
6
+ # @param name [String] Name of the channel
7
+ # @return [Channel] The channel you requested, if it exists
8
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-channels
9
+ # @example Get channel 0123456789012345
10
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
11
+ # @client.channel("0123456789012345")
12
+ def channel(name, options={})
13
+ enhance( get("channels/#{name}", options), with: ChannelMethods )
14
+ end
3
15
 
4
- # Retrieve list of channels
5
- # WARNING: This method uses calls not officially supported by Mobile Devices.
6
- #
7
- # @return [Array of Hashie::Mash] Channels
8
- def channels(reload = false)
9
- return @channels if @channels && !reload
10
- page = 1
11
- limit = 100
12
- channels = []
13
- while (slice = connection.get(connection.build_url("channels", :per_page => limit, :page => page)).body).size > 0
14
- page += 1
15
- channels += slice.map!{|hash| hash.values.first} if slice.size > 0
16
- slice.size < limit ? break : sleep(1)
16
+ # Search channels
17
+ #
18
+ # @param search_term [String] The term to search for
19
+ # @return [Array] A list of channels matching the search term
20
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-channels
21
+ # @example Search for 'com.mdi.services.adminProtocol' in the channels
22
+ # @client = CloudConnect::Client.new(:account => 'foor', :token => 'bar')
23
+ # @client.search_channels
24
+ def search_channels(search_term, options={})
25
+ enhance( get("channels?q=#{search_term}", options), with: ChannelMethods )
26
+ end
27
+
28
+ # Get channels
29
+ #
30
+ # @return [Array] A list of all channels
31
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0003-channels
32
+ # @example List all channels
33
+ # @client = CloudConnect::Client.new(:account => 'foo', :token => 'bar')
34
+ # @client.channels
35
+ def channels(options={})
36
+ enhance( get("channels", options), with: ChannelMethods )
37
+ end
38
+ alias :list_channels :channels
39
+
40
+ # Create a channel
41
+ #
42
+ # @param name [String] Name of the channel
43
+ # @param options [Hash] A customizable set of options
44
+ # @options options [Integer] :msgttl The delay in seconds before the message is considered expired (and will not be sent)
45
+ # @options options [Integer] :unitack The delay in seconds for acknowledgment by the asset (after the message has been sent)
46
+ # @options options [Integer] :serverack The delay in seconds for acknowledgment by the server (after the message has been sent)
47
+ # @return [Channel] Your newly created channel
48
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0007-channels#create_a_new_channel
49
+ # @example Create a new Channel
50
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
51
+ # @client.create_channel("weather")
52
+ def create_channel(name, options={})
53
+ enhance( post("channels", options.merge({:name => name})), with: ChannelMethods )
17
54
  end
18
- @channels = channels.sort_by(&:channel)
19
- end
20
55
 
56
+ # Update a channel
57
+ #
58
+ # @param name [String] Name of the channel
59
+ # @param options [Hash] A customizable set of options
60
+ # @options options [Integer] :msgttl The delay in seconds before the message is considered expired (and will not be sent)
61
+ # @options options [Integer] :unitack The delay in seconds for acknowledgment by the asset (after the message has been sent)
62
+ # @options options [Integer] :serverack The delay in seconds for acknowledgment by the server (after the message has been sent)
63
+ # @return [Channel] Your newly updated channel
64
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0007-channel#update_a_channel
65
+ # @example Update a Channel
66
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
67
+ # @client.create_channel("weather", :msgttl => 123, ...)
68
+ def update_channel(name, options={})
69
+ enhance( put("channels/#{name}", options.merge({:name => name})), with: ChannelMethods )
70
+ end
71
+
72
+ # Delete a single channel
73
+ #
74
+ # @param name [String] Name fo the channel
75
+ # @return [Response] A response object with status
76
+ # @see http://wordsabout.it/mobile-devices/cloudconnect-user-documentation/cc-0006-channels#delete_a_channel
77
+ # @example Delete the CUSTOM_SENSOR_TEMP channel
78
+ # @client = CloudConnect::CloudConnect.new(:account => 'foo', :token => 'bar')
79
+ # @client.delete_channel("com.acmecorp.weather")
80
+ def delete_channel(name, options={})
81
+ delete("channels/#{name}", options, true)
82
+ end
83
+
84
+ module ChannelMethods
85
+ extend CustomMethods
86
+ end
87
+ end
21
88
  end
22
89
  end
@@ -0,0 +1,54 @@
1
+ module CloudConnect
2
+ class Client
3
+ module Configurations
4
+ # Get a configuration
5
+ #
6
+ # @param id [String] ID of the configuration
7
+ # @return [Configuration] The configuration you requested, if it exists
8
+ def configuration(id, options={})
9
+ enhance( get("configs/#{id}", options), with: ConfigurationMethods )
10
+ end
11
+
12
+ # Search configurations
13
+ #
14
+ # @param search_term [String] The term to search for
15
+ # @return [Array] A list of configurations matching the search term
16
+ def search_configurations(search_term, options={})
17
+ enhance( get("configs?q=#{search_term}", options), with: ConfigurationMethods )
18
+ end
19
+
20
+ # Create a configuration
21
+ #
22
+ # @param name [String] Name of the configuration
23
+ # @options options [Hash] :data JSON data of the config
24
+ # @options options [Array] :imeis list of assets concerned by this configuration
25
+ # @return [Field] Your newly created configuration
26
+ def create_configuration(name, options={})
27
+ enhance( post("configs", options.merge(name: name)), with: ConfigurationMethods )
28
+ end
29
+
30
+ # Update a configuration
31
+ #
32
+ # @param id [String] Id of the configuration
33
+ # @options options [String] Name of the configuration
34
+ # @options options [Hash] :data JSON data of the config
35
+ # @options options [Array] :imeis list of assets concerned by this configuration
36
+ # @return [Field] Your newly created configuration
37
+ def update_configuration(id, options={})
38
+ enhance( put("configs/#{id}", options), with: ConfigurationMethods )
39
+ end
40
+
41
+ # Get all configurations
42
+ #
43
+ # @return [Array] A list of all configurations
44
+ def configurations(options={})
45
+ enhance( get("configs", options), with: ConfigurationMethods )
46
+ end
47
+ alias :list_configurations :configurations
48
+
49
+ module ConfigurationMethods
50
+ extend CustomMethods
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ module CustomMethods
2
+ # @private
3
+ def extended(base)
4
+ # FIXME: Useless time consuming (especially for arrays)...
5
+ base.class.send(:attr_accessor, :_client) unless base.respond_to?(:_client)
6
+ end
7
+
8
+ # @private
9
+ # By extending CustomMethods in YourModule, you are able to call
10
+ # YourModule.apply_to(object_or_array) to add YourModule methods to the
11
+ # object or to all objects in the array.
12
+ def apply_to(receiver, client_opts)
13
+ case receiver
14
+ when Array
15
+ receiver.each{|a| a.extend self; a._client = client_opts[:client]}
16
+ when Hashie::Mash
17
+ receiver.extend self; receiver._client = client_opts[:client]
18
+ end
19
+ end
20
+ end