brocade_io 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2f2bcbd17b72290ed22df4ba0ebcee354e6b1a1a47cdf5ad2c72259679cae1f1
4
+ data.tar.gz: 8bd4b0e8c6e1609bca32671a04863b071639b02328c8780d6a240ac3d181aa55
5
+ SHA512:
6
+ metadata.gz: cef03c811486a702d0429068017cb4e1d0a2c014ceac7ccb41dbb2844f187f4f3d6d7fcadede4552b9dc6827f9ef7dd665c7827f1d1bfcb9a6735f90c3a2d54a
7
+ data.tar.gz: 00ce8a6675e0513c7836da6b9c8a2b4218e0f291121109cacdbe2f8212a00f87b72eda915facabb213b0d21d8317b9178b4aed5670681c84c7e8a100062127fb
@@ -0,0 +1,3 @@
1
+ ## 0.0.1 (2014-03-02)
2
+
3
+ - First release
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014-2019 Andrew Kane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # BrocadeIo
2
+
3
+ Ruby client for [Brocade.io](https://www.brocade.io/) - a free and open product database
4
+
5
+ ## Get Started
6
+
7
+ Add this line to your application’s Gemfile:
8
+
9
+ ```ruby
10
+ gem 'brocade_io'
11
+ ```
12
+
13
+ Create a client
14
+
15
+ ```ruby
16
+ brocade_io = BrocadeIo.new
17
+ ```
18
+
19
+ Get an item
20
+
21
+ ```ruby
22
+ item = brocade_io.item("013562610020") # or nil if not found
23
+ item.gtin14
24
+ item.brand_name
25
+ item.name
26
+ item.size
27
+ ```
28
+
29
+ Create or update an item
30
+
31
+ ```ruby
32
+ brocade_io.update_item("000000000000", {name: "Test"})
33
+ ```
34
+
35
+ List items
36
+
37
+ ```ruby
38
+ brocade_io.items
39
+ ```
40
+
41
+ Returns the first 100 items.
42
+
43
+ To get all items, use:
44
+
45
+ ```ruby
46
+ brocade_io.paginated_items do |item|
47
+ item.gtin14
48
+ end
49
+ ```
50
+
51
+ Search items
52
+
53
+ ```ruby
54
+ brocade_io.items(query: "peanut butter")
55
+ ```
56
+
57
+ Add an image (NB not currently supported)
58
+
59
+ ```ruby
60
+ image = Faraday::UploadIO.new("ice_cream.jpg", "image/jpeg")
61
+ image_type = "scan" # or "photo"
62
+ brocade_io.add_image("000000000000", image, image_type)
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ Everyone is encouraged to help improve this project. Here are a few ways you can help:
68
+
69
+ - [Report bugs](https://github.com/ferrisoxide/brocade_io/issues)
70
+ - Fix bugs and [submit pull requests](https://github.com/ferrisoxide/brocade_io/pulls)
71
+ - Write, clarify, or fix documentation
72
+ - Suggest or add new features
@@ -0,0 +1,80 @@
1
+ require "json"
2
+ require "faraday"
3
+ require "hashie"
4
+ require "brocade_io/version"
5
+ require "brocade_io/item"
6
+
7
+ class BrocadeIo
8
+
9
+ def initialize(options = {})
10
+ @host = options[:host] || "https://www.brocade.io"
11
+ @version = options[:version] || 1
12
+ end
13
+
14
+ def item(gtin)
15
+ response = http_client.get("/api/items/#{gtin}?version=#{@version}")
16
+ if response.success?
17
+ Item.new(JSON.parse(response.body))
18
+ end
19
+ end
20
+
21
+ def update_item(gtin, attributes)
22
+ response = http_client.put("/api/items/#{gtin}?version=#{@version}", attributes)
23
+ if response.success?
24
+ Item.new(JSON.parse(response.body))
25
+ end
26
+ end
27
+
28
+ def add_image(gtin, image, image_type)
29
+ params = {
30
+ gtin: gtin,
31
+ image: image,
32
+ perspective: image_type
33
+ }
34
+ response = http_client.post("/api/items/#{gtin}/images?version=#{@version}", params)
35
+ if response.success?
36
+ JSON.parse(response.body)
37
+ end
38
+ end
39
+
40
+ def items(params = {})
41
+ response = http_client.get("/api/items?version=#{@version}", params)
42
+ if response.success?
43
+ JSON.parse(response.body).map do |item|
44
+ Item.new(item)
45
+ end
46
+ end
47
+ end
48
+
49
+ def paginated_items(params)
50
+ response = http_client.get("/api/items?version=#{@version}", params)
51
+ loop do
52
+ links = {}
53
+ if response.success?
54
+ JSON.parse(response.body).map do |item|
55
+ yield Item.new(item)
56
+ end
57
+
58
+ # https://gist.github.com/davidcelis/5896686
59
+ response.headers['Link'].to_s.split(',').each do |link|
60
+ link.strip!
61
+ parts = link.match(/<(.+)>; *rel="(.+)"/)
62
+ links[parts[2]] = parts[1]
63
+ end
64
+ end
65
+
66
+ break unless links["next"] && (response = http_client.get(links["next"]))
67
+ end
68
+ end
69
+
70
+ protected
71
+
72
+ def http_client
73
+ Faraday.new(url: @host) do |conn|
74
+ conn.request :multipart
75
+ conn.request :url_encoded
76
+ conn.adapter :net_http
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,4 @@
1
+ class BrocadeIo
2
+ class Item < Hashie::Mash
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class BrocadeIo
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brocade_io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kane
8
+ - Tom Tuddenham
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: hashie
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: minitest
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description:
85
+ email: ferrisoxide@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - LICENSE.txt
92
+ - README.md
93
+ - lib/brocade_io.rb
94
+ - lib/brocade_io/item.rb
95
+ - lib/brocade_io/version.rb
96
+ homepage: https://github.com/ferrisoxide/brocade_io
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '2.4'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Ruby client for Brocade.io
119
+ test_files: []