genesis_client 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: 8329c2d48302aaf273c20f40f8e18fb15654651b
4
+ data.tar.gz: 7cbe9bca58f4794abd8c28949522da63620d7322
5
+ SHA512:
6
+ metadata.gz: f8f7b8100de090ea8ce4295457ca66b5ff581aa49e53033a029172b706f4db1cbd83360b19385e42762536c4ac8a336da5a103a2620be8e536335b03954679b7
7
+ data.tar.gz: a1739d86965268510804425287acfe4971349ac6a48cffa8292119b7910758cd15c3508429e67aad94b70f7f421d336d7f889d5821d4b36566385c38e55559d1
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --order random
3
+ --format documentation
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ Exclude:
5
+ - 'bin/*'
6
+
7
+ Style/EmptyLinesAroundBlockBody:
8
+ Enabled: false
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+ Exclude:
13
+ - 'spec/**/*'
14
+
15
+ Metrics/LineLength:
16
+ Max: 120
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.1.8
5
+ - 2.2.4
6
+ - 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in genesis_client.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Shopify
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,41 @@
1
+ # GenesisClient
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/genesis_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'genesis_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install genesis_client
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/genesis_client.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'genesis_client'
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,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rubocop", "rubocop")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'genesis_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'genesis_client'
8
+ spec.version = GenesisClient::VERSION
9
+ spec.authors = ['David Radcliffe']
10
+ spec.email = ['david.radcliffe@shopify.com']
11
+
12
+ spec.summary = 'Ruby client library for the Genesis API'
13
+ spec.homepage = 'https://github.com/Shopify/genesis_client'
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.11'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'webmock', '~> 1.21.0'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'rubocop', '~> 0.39.0'
27
+
28
+ spec.add_dependency 'faraday', '~> 0.9.0'
29
+ spec.add_dependency 'faraday_middleware', '~> 0.9.0'
30
+ spec.add_dependency 'hashie', '~> 3.0'
31
+ end
@@ -0,0 +1,6 @@
1
+ require 'genesis_client/version'
2
+ require 'genesis_client/client'
3
+
4
+ module GenesisClient
5
+ USER_AGENT = "Shopify/genesis_client/#{GenesisClient::VERSION}".freeze
6
+ end
@@ -0,0 +1,57 @@
1
+ require 'genesis_client/devices'
2
+ require 'genesis_client/remote_actions'
3
+ require 'faraday_middleware'
4
+
5
+ module GenesisClient
6
+ class Client
7
+ def initialize(options = {})
8
+ @endpoint = options[:endpoint].to_s
9
+ @token = options[:token].to_s
10
+ raise ArgumentError, ":endpoint can't be blank" if @endpoint.empty?
11
+ raise ArgumentError, ":token can't be blank" if @token.empty?
12
+ end
13
+
14
+ include GenesisClient::Devices
15
+ include GenesisClient::RemoteActions
16
+
17
+ private
18
+
19
+ def get(path, options = {})
20
+ request(:get, path, options)
21
+ end
22
+
23
+ def post(path, data = {})
24
+ request(:post, path, data)
25
+ end
26
+
27
+ def put(path, data = {})
28
+ request(:put, path, data)
29
+ end
30
+
31
+ def request(method, path, data = {})
32
+ res = connection.send(method, "api/#{path}", data)
33
+ if res.success? && !res.body.empty? && res.body != ' '
34
+ res.body
35
+ else
36
+ res
37
+ end
38
+ end
39
+
40
+ # Returns a Faraday::Connection object
41
+ #
42
+ # @return [Faraday::Connection]
43
+ def connection
44
+ @connection ||= Faraday.new @endpoint do |f|
45
+ f.request :json
46
+ f.headers[:user_agent] = GenesisClient::USER_AGENT
47
+ f.headers['Authorization'] = "Token token=\"#{@token}\""
48
+
49
+ # f.response :logger
50
+ f.response :mashify
51
+ f.response :json, content_type: /\bjson$/
52
+
53
+ f.adapter Faraday.default_adapter
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,44 @@
1
+ module GenesisClient
2
+ module Devices
3
+ # Receive a list of all Devices.
4
+ #
5
+ # @return [Array<Hashie::Mash>] Array of hashes representing devices.
6
+ # @example
7
+ # client = GenesisClient::Client.new
8
+ # client.devices
9
+ def devices(type = nil)
10
+ (type.nil? ? get('/devices') : get("/devices?type=#{type}"))['devices']
11
+ end
12
+ alias list_devices devices
13
+
14
+ # Receive a single Device.
15
+ #
16
+ # @return [Hashie::Mash] Hash representing the device.
17
+ # @param sku [String] The SKU of the device
18
+ # @example
19
+ # client = GenesisClient::Client.new
20
+ # client.device('UNK-12345534')
21
+ def device(sku)
22
+ get("/devices/#{sku}")['device']
23
+ end
24
+
25
+ # Modify an existing Device.
26
+ #
27
+ # @return [Hashie::Mash] Hash representing the device
28
+ # @param sku [Integer] The SKU of the device
29
+ # @param data [Hash] Device attributes to update
30
+ def update_device(sku, data)
31
+ put("/devices/#{sku}", data)['device']
32
+ end
33
+
34
+ # Create a new Log for a Device.
35
+ #
36
+ # @return [Hashie::Mash] Hash representing the log
37
+ # @param sku [Integer] The SKU of the device
38
+ # @param message [String] Log message
39
+ def create_device_log(sku, message)
40
+ data = { message: message }
41
+ post("/devices/#{sku}/logs", data)['log']
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,47 @@
1
+ module GenesisClient
2
+ module RemoteActions
3
+ # Receive a list of all Devices.
4
+ #
5
+ # @return [Array<Hashie::Mash>] Array of hashes representing remote actions.
6
+ # @example
7
+ # client = GenesisClient::Client.new
8
+ # client.remote_actions
9
+ def remote_actions(zone)
10
+ filters = {
11
+ zone: zone
12
+ }
13
+ get('/remote_actions', filters)['remote_actions']
14
+ end
15
+ alias list_remote_actions remote_actions
16
+
17
+ # Receive a single Remote Action.
18
+ #
19
+ # @return [Hashie::Mash] Hash representing the remote action.
20
+ # @param id [String, Integer] The id of the remote action
21
+ # @example
22
+ # client = GenesisClient::Client.new
23
+ # client.remote_action('234')
24
+ def remote_action(id)
25
+ get("/remote_actions/#{id}")['remote_action']
26
+ end
27
+
28
+ # Modify an existing Remote Action.
29
+ #
30
+ # @return [Hashie::Mash] Hash representing the remote action.
31
+ # @param id [String, Integer] The id of the remote action
32
+ # @param data [Hash] Remote Action attributes to update
33
+ def update_remote_action(id, data)
34
+ put("/remote_actions/#{id}", data)['remote_action']
35
+ end
36
+
37
+ # Create a new Log for a Remote Action.
38
+ #
39
+ # @return [Hashie::Mash] Hash representing the log
40
+ # @param id [String, Integer] The id of the remote action
41
+ # @param message [String] Log message
42
+ def create_remote_action_log(id, message)
43
+ data = { message: message }
44
+ post("/remote_actions/#{id}/logs", data)['log']
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module GenesisClient
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genesis_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Radcliffe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-07 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.21.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.21.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.39.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.39.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday_middleware
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: hashie
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ description:
140
+ email:
141
+ - david.radcliffe@shopify.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - bin/console
155
+ - bin/rspec
156
+ - bin/rubocop
157
+ - bin/setup
158
+ - genesis_client.gemspec
159
+ - lib/genesis_client.rb
160
+ - lib/genesis_client/client.rb
161
+ - lib/genesis_client/devices.rb
162
+ - lib/genesis_client/remote_actions.rb
163
+ - lib/genesis_client/version.rb
164
+ homepage: https://github.com/Shopify/genesis_client
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.6.3
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Ruby client library for the Genesis API
188
+ test_files: []
189
+ has_rdoc: