simplemdm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ff715d54ff2744ebdbf620dc677ac39b6fb38b0
4
+ data.tar.gz: 0a061ac1832772b2bf00a7e6219a406ca0cc1d50
5
+ SHA512:
6
+ metadata.gz: d18c80f0f50495cbfdc54d249747ae7f036c1f22be53b435d4fa706dfbc994a21cc320657d72e3950e1daced09dd54bf2079362ca4b787a701dcde973b4c8559
7
+ data.tar.gz: 55d393d7d50bd70efc3905d8c736985aa2e48c8664d2b5943e4450f3c2305c91824e077d0a4c7c729196ddeff1d76e05a3b34ff3ba85d23cc42c615fc5b6dc0d
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.DS_Store
12
+ simplemdm*.gem
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simplemdm-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # SimpleMDM Ruby bindings
2
+
3
+ This is a lightweight SDK that acts as a launching point for integrating ruby-based applications with SimpleMDM. The native API is a RESTful JSON implementation. These bindings wrap the API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'simplemdm-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simplemdm-ruby
20
+
21
+ ## Usage
22
+
23
+ Full documentation is available here: (http://www.simplemdm.com/docs/api/)[http://www.simplemdm.com/docs/api/]
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/SimpleMDM/simplemdm-ruby/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simplemdm/ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ require 'simplemdm/version'
2
+ require 'simplemdm/simplemdm'
3
+ require 'simplemdm/base'
4
+ require 'simplemdm/account'
5
+ require 'simplemdm/app'
6
+ require 'simplemdm/app_group'
7
+ require 'simplemdm/device'
8
+ require 'simplemdm/device_group'
9
+ require 'simplemdm/installed_app'
@@ -0,0 +1,18 @@
1
+ require 'singleton'
2
+
3
+ module SimpleMDM
4
+ class Account < Hash
5
+ include Singleton
6
+
7
+ def initialize
8
+ hash, code = SimpleMDM::Base.fetch("account")
9
+
10
+ self['name'] = hash['data']['attributes']['name']
11
+ end
12
+
13
+ def name
14
+ self['name']
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,69 @@
1
+ module SimpleMDM
2
+ class App < Base
3
+
4
+ def build(hash = nil)
5
+ @dirty = false
6
+ @binary_data = nil
7
+
8
+ super
9
+ end
10
+
11
+ def self.all
12
+ hash, code = fetch("apps")
13
+
14
+ hash['data'].collect { |d| build d }
15
+ end
16
+
17
+ def self.find(id)
18
+ hash, code = fetch("apps/#{id}")
19
+
20
+ build hash['data']
21
+ end
22
+
23
+ def binary=(val)
24
+ raise "binary must be a File object" unless val.kind_of? File
25
+
26
+ @dirty = true
27
+ @binary_file = val
28
+ end
29
+
30
+ def name=(val)
31
+ if val != self.name
32
+ @dirty = true
33
+ end
34
+
35
+ self['name'] = val
36
+ end
37
+
38
+ def save
39
+ if @dirty || new?
40
+ params = {}
41
+ params[:name] = self.name
42
+ params[:binary] = @binary_file unless @binary_file.nil?
43
+
44
+ if new?
45
+ hash, code = fetch("apps", :post, params)
46
+
47
+ self.id = hash['data']['id']
48
+ self.merge!(hash['data']['attributes'])
49
+ else
50
+ hash, code = fetch("apps/#{self.id}", :patch, params)
51
+ end
52
+
53
+ @dirty = false
54
+ @binary_file = nil
55
+ end
56
+
57
+ self
58
+ end
59
+
60
+ def destroy
61
+ raise "You cannot delete an app that hasn't been created yet." if new?
62
+
63
+ hash, code = fetch("apps/#{self.id}", :delete)
64
+
65
+ code == 204
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,136 @@
1
+ module SimpleMDM
2
+ class AppGroup < Base
3
+
4
+ def build(hash = nil)
5
+ @dirty = false
6
+
7
+ super
8
+ end
9
+
10
+ def self.all
11
+ hash, code = fetch("app_groups")
12
+
13
+ hash['data'].collect { |d| build d }
14
+ end
15
+
16
+ def self.find(id)
17
+ hash, code = fetch("app_groups/#{id}")
18
+
19
+ build hash['data']
20
+ end
21
+
22
+ def save
23
+ if @dirty || new?
24
+ params = {}
25
+ params[:name] = self.name unless self.name.nil?
26
+ params[:auto_deploy] = self.auto_deploy unless self.auto_deploy.nil?
27
+
28
+ if new?
29
+ hash, code = fetch("app_groups", :post, params)
30
+
31
+ self.id = hash['data']['id']
32
+ self.merge!(hash['data']['attributes'])
33
+ else
34
+ fetch("app_groups/#{self.id}", :patch, params)
35
+ end
36
+
37
+ @dirty = false
38
+ end
39
+
40
+ self
41
+ end
42
+
43
+ def name=(val)
44
+ if val != self.name
45
+ @dirty = true
46
+ end
47
+
48
+ self['name'] = val
49
+ end
50
+
51
+ def auto_deploy=(val)
52
+ if val != self.auto_deploy
53
+ @dirty = true
54
+ end
55
+
56
+ self['auto_deploy'] = val
57
+ end
58
+
59
+ def destroy
60
+ raise "You cannot delete an app group that hasn't been created yet" if new?
61
+
62
+ hash, code = fetch("app_groups/#{self.id}")
63
+
64
+ code == 204
65
+ end
66
+
67
+ def add_app(app)
68
+ raise "You must save this app group before changing associations" if new?
69
+ raise "The object you provided is not an app" unless app.kind_of?(SimpleMDM::App)
70
+ raise "You must save the app before associating it" if app.id.nil?
71
+
72
+ hash, code = fetch("app_groups/#{self.id}/apps/#{app.id}", :post)
73
+
74
+ if code == 204
75
+ self['app_ids'] = self['app_ids'] | [app.id]
76
+ true
77
+ else
78
+ false
79
+ end
80
+ end
81
+
82
+ def remove_app(app)
83
+ raise "You must save this app group before changing associations." if new?
84
+ raise "The object you provided is not an app" unless app.kind_of?(SimpleMDM::App)
85
+ raise "The app you provided doesn't exist" if app.id.nil?
86
+
87
+ hash, code = fetch("app_groups/#{self.id}/apps/#{app.id}", :delete)
88
+
89
+ if code == 204
90
+ self['app_ids'].delete(app.id)
91
+ true
92
+ else
93
+ false
94
+ end
95
+ end
96
+
97
+ def add_device_group(device_group)
98
+ raise "You must save this app group before changing associations." if new?
99
+ raise "The object you provided is not a device group" unless device_group.kind_of?(SimpleMDM::DeviceGroup)
100
+ raise "You must save the device_group before associating it" if device_group.id.nil?
101
+
102
+ hash, code = fetch("app_groups/#{self.id}/device_groups/#{device_group.id}", :post)
103
+
104
+ if code == 204
105
+ self['device_group_ids'] = self['device_group_ids'] | [device_group.id]
106
+ true
107
+ else
108
+ false
109
+ end
110
+ end
111
+
112
+ def remove_device_group(device_group)
113
+ raise "You must save this app group before changing associations" if new?
114
+ raise "The object you provided is not a device group" unless device_group.kind_of?(SimpleMDM::DeviceGroup)
115
+ raise "The device group you provided doesn't exist" if device_group.id.nil?
116
+
117
+ hash, code = fetch("app_groups/#{self.id}/device_groups/#{device_group.id}", :delete)
118
+
119
+ if code == 204
120
+ self['device_group_ids'].delete(device_group.id)
121
+ true
122
+ else
123
+ false
124
+ end
125
+ end
126
+
127
+ def push_apps
128
+ raise "You cannot push apps for an app group that hasn't been created yet" if new?
129
+
130
+ hash, code = fetch("app_groups/#{self.id}/push_apps", :post)
131
+
132
+ code == 202
133
+ end
134
+
135
+ end
136
+ end
@@ -0,0 +1,69 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'hashie'
4
+
5
+ module SimpleMDM
6
+ class Base < Hashie::Mash
7
+
8
+ def self.build(hash = nil)
9
+ if hash
10
+ attrs = {}
11
+
12
+ if hash['id']
13
+ attrs[:id] = hash['id']
14
+ end
15
+
16
+ if hash['attributes']
17
+ attrs.merge!(hash['attributes'])
18
+ end
19
+
20
+ if hash['relationships']
21
+ if hash['relationships']['device_group']
22
+ attrs['device_group_id'] = hash['relationships']['device_group']['data']['id']
23
+ end
24
+
25
+ if hash['relationships']['device_groups']
26
+ attrs['device_group_ids'] = hash['relationships']['device_groups']['data'].collect { |o| o['id'] }
27
+ end
28
+
29
+ if hash['relationships']['apps']
30
+ attrs['app_ids'] = hash['relationships']['apps']['data'].collect { |o| o['id'] }
31
+ end
32
+ end
33
+
34
+ new attrs
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def new?
41
+ self.id.nil?
42
+ end
43
+
44
+ def self.fetch(method, verb = :get, params = {})
45
+ headers = { 'SIMPLEMDM-CLIENT-VERSION' => SimpleMDM::VERSION }
46
+ url = SimpleMDM.api_url + method
47
+ if [:get, :delete].include? verb
48
+ resp = RestClient.send(verb, url, headers)
49
+ else
50
+ resp = RestClient.send(verb, url, params, headers)
51
+ end
52
+
53
+ begin
54
+ hash = JSON.parse(resp)
55
+ rescue JSON::ParserError
56
+ hash = nil
57
+ end
58
+
59
+ code = resp.code
60
+
61
+ return hash, code
62
+ end
63
+
64
+ def fetch(method, verb = :get, params = {})
65
+ self.class.fetch(method, verb, params)
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,52 @@
1
+ module SimpleMDM
2
+ class Device < Base
3
+
4
+ def self.all
5
+ hash, code = fetch("devices")
6
+
7
+ hash['data'].collect { |d| build d }
8
+ end
9
+
10
+ def self.find(id)
11
+ hash, code = fetch("devices/#{id}")
12
+
13
+ build hash['data']
14
+ end
15
+
16
+ def installed_apps
17
+ raise "You cannot retrieve installed apps for a device that hasn't been created yet." if new?
18
+
19
+ hash, code = fetch("devices/#{id}/installed_apps")
20
+
21
+ hash['data'].collect { |a| InstalledApp.build a }
22
+ end
23
+
24
+ def lock(options = {})
25
+ params = options.delete_if { |k,v| ![:message, :phone_number, :pin].include?(k) }
26
+
27
+ hash, code = fetch("devices/#{id}/lock", :post, params)
28
+
29
+ code == 202
30
+ end
31
+
32
+ def clear_passcode
33
+ hash, code = fetch("devices/#{id}/clear_passcode", :post)
34
+
35
+ code == 202
36
+ end
37
+
38
+ def wipe
39
+ hash, code = fetch("devices/#{id}/wipe", :post)
40
+
41
+ code == 202
42
+ end
43
+
44
+ def push_apps
45
+ hash, code = fetch("devices/#{id}/push_apps", :post)
46
+
47
+ code == 202
48
+ end
49
+
50
+
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+ module SimpleMDM
2
+ class DeviceGroup < Base
3
+
4
+ def self.all
5
+ hash, code = fetch("device_groups")
6
+
7
+ hash['data'].collect { |d| build d }
8
+ end
9
+
10
+ def self.find(id)
11
+ hash, code = fetch("device_groups/#{id}")
12
+
13
+ build hash['data']
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleMDM
2
+ class InstalledApp < Base
3
+ end
4
+ end
@@ -0,0 +1,25 @@
1
+ module SimpleMDM
2
+
3
+ @BASE_URL = 'a.simplemdm.com/api/v1/'
4
+
5
+ def self.api_key=(value)
6
+ @API_KEY = value
7
+ end
8
+
9
+ def self.api_key
10
+ @API_KEY
11
+ end
12
+
13
+ def self.base_url=(value)
14
+ @BASE_URL = value
15
+ end
16
+
17
+ def self.base_url
18
+ @BASE_URL
19
+ end
20
+
21
+ def self.api_url
22
+ "https://#{@API_KEY}:@#{@BASE_URL}"
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleMDM
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simplemdm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simplemdm"
8
+ spec.version = SimpleMDM::VERSION
9
+ spec.authors = ["Taylor Boyko"]
10
+ spec.email = ["taylor@wrprojects.com"]
11
+
12
+ spec.summary = %q{Ruby bindings for the SimpleMDM API.}
13
+ spec.homepage = "http://www.simplemdm.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "rest-client", "~> 1.8"
24
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplemdm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taylor Boyko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-20 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.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ description:
56
+ email:
57
+ - taylor@wrprojects.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CODE_OF_CONDUCT.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/.DS_Store
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/.DS_Store
72
+ - lib/simplemdm.rb
73
+ - lib/simplemdm/.DS_Store
74
+ - lib/simplemdm/account.rb
75
+ - lib/simplemdm/app.rb
76
+ - lib/simplemdm/app_group.rb
77
+ - lib/simplemdm/base.rb
78
+ - lib/simplemdm/device.rb
79
+ - lib/simplemdm/device_group.rb
80
+ - lib/simplemdm/installed_app.rb
81
+ - lib/simplemdm/simplemdm.rb
82
+ - lib/simplemdm/version.rb
83
+ - simplemdm.gemspec
84
+ homepage: http://www.simplemdm.com
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.4.6
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Ruby bindings for the SimpleMDM API.
108
+ test_files: []