scalablepress 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
+ SHA1:
3
+ metadata.gz: b229b07dae50ac768c110eb2c3a41fb648f706ad
4
+ data.tar.gz: 67c8fa82e3c7634cce9701b434bbfba800a8eba6
5
+ SHA512:
6
+ metadata.gz: 0231b69684ee06c880a2934e7f81d0f1aa20ed2f1a7f9ddab85c644ff13aedf55879111fa32c735f4c6566b18161cb2501f0c41ecb77c6a20b28bc5aa0997993
7
+ data.tar.gz: d5ccb1b91082f5243793758eed4fb8f334659494abbcf0bcd089b2a822d75a77432063dffe27b6e0bbf3a4ddcf0b2ffd3c6393fa3285c88b11bafde1a641f4a8
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.swp
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scalablepress.gemspec
4
+ gemspec
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ scalablepress (0.0.1)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ domain_name (0.5.23)
11
+ unf (>= 0.0.5, < 1.0.0)
12
+ http-cookie (1.0.2)
13
+ domain_name (~> 0.5)
14
+ mime-types (2.4.3)
15
+ minitest (5.5.1)
16
+ netrc (0.10.3)
17
+ rake (10.4.2)
18
+ rest-client (1.8.0)
19
+ http-cookie (>= 1.0.2, < 2.0)
20
+ mime-types (>= 1.16, < 3.0)
21
+ netrc (~> 0.7)
22
+ unf (0.1.4)
23
+ unf_ext
24
+ unf_ext (0.0.6)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.7)
31
+ minitest
32
+ rake (~> 10.0)
33
+ scalablepress!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Oren Mazor
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 oren mazor
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,31 @@
1
+ # Scalablepress
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'scalablepress'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scalablepress
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/scalablepress/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "tests"
6
+ t.test_files = FileList['tests/test*.rb']
7
+ t.verbose = true
8
+ end
9
+
@@ -0,0 +1,13 @@
1
+ require "scalablepress/version"
2
+ require "scalablepress/api"
3
+ Dir[File.dirname(__FILE__) + '/scalablepress/resources/*.rb'].each {|file| require file }
4
+
5
+ module Scalablepress
6
+ def self.API_KEY
7
+ @API_KEY
8
+ end
9
+
10
+ def self.API_KEY=(key)
11
+ @API_KEY=key
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'rest-client'
2
+
3
+ module Scalablepress
4
+ class API
5
+ def self.get(path)
6
+ JSON.parse(RestClient.get("https://#{Scalablepress::API_KEY}:@api.scalablepress.com/v2/#{path}"))
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ module Scalablepress
2
+ class Category
3
+ attr_reader :name
4
+ attr_reader :category_id
5
+
6
+ def initialize(params)
7
+ @name = params["name"]
8
+ @category_id = params["categoryId"]
9
+ end
10
+
11
+ def products
12
+ API.get("categories/#{@category_id}")["products"].map {|x| Product.new(x) }
13
+ end
14
+
15
+ def self.find_by_id(id)
16
+ all.select {|c| c.category_id == id }.first
17
+ end
18
+
19
+ def self.all
20
+ result = API.get("categories")
21
+ result.map { |params| Category.new(params) }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module Scalablepress
2
+ class Product
3
+ attr_reader :name
4
+ attr_reader :product_id
5
+
6
+ def initialize(params)
7
+ @name = params["name"]
8
+ @product_id = params["id"]
9
+ end
10
+
11
+ def product_info
12
+ return @product_info if @product_info
13
+ @product_info = API.get("products/#{@product_id}")
14
+ end
15
+
16
+ def colors
17
+ @colors = product_info["colors"]
18
+ @colors.map {|c| c["name"] }
19
+ end
20
+
21
+ def images_for_color(color)
22
+ matched_color = product_info["colors"].select {|c| c["name"] == color }.first
23
+ raise "#{color} is invalid color selection for #{colors.join(", ")}" unless matched_color
24
+ images = matched_color["images"]
25
+ raise "Found no images for #{color}!" unless images.any?
26
+ images.map {|x| x["url"] }
27
+ end
28
+
29
+ def self.all
30
+ Category.all.map {|c| c.products }.flatten
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Scalablepress
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scalablepress/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scalablepress"
8
+ spec.version = Scalablepress::VERSION
9
+ spec.authors = ["oren mazor"]
10
+ spec.email = ["oren.mazor@gmail.com"]
11
+ spec.summary = %q{quick and dirty wrapper for the scalable press api}
12
+ spec.description = %q{quick and dirty wrapper for the scalable press api}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_dependency "rest-client"
25
+ end
@@ -0,0 +1,17 @@
1
+ require "minitest/autorun"
2
+ require "scalablepress"
3
+ require File.dirname(__FILE__) + '/test_helper'
4
+
5
+ class TestCategory < Minitest::Test
6
+ def test_we_get_categories
7
+ categories = Scalablepress::Category.all
8
+ assert categories.any?
9
+ assert categories.first.is_a?(Scalablepress::Category)
10
+ end
11
+
12
+ def test_category_find
13
+ category = Scalablepress::Category.find_by_id("sweatshirts")
14
+
15
+ assert category.name == "Sweatshirts"
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ Scalablepress::API_KEY = ENV["SCALABLE_PRESS_API_KEY"]
@@ -0,0 +1,47 @@
1
+ require "minitest/autorun"
2
+ require "scalablepress"
3
+ require File.dirname(__FILE__) + '/test_helper'
4
+
5
+ class TestProduct < Minitest::Test
6
+ def setup
7
+ @products = Scalablepress::Category.find_by_id("ladies-tank-tops").products
8
+ end
9
+
10
+ def test_we_get_all_products
11
+ assert @products.any?
12
+ assert @products.first.is_a?(Scalablepress::Product)
13
+ end
14
+
15
+ def test_a_product_knows_its_colors
16
+ matching_shirts = @products.select {|p| p.name == "Bella Sheer Triblend Racerback"}
17
+ assert matching_shirts.count == 1
18
+ expected = ["Charcoal Triblend", "Emerald Triblend", "Grey Triblend", "Blue Triblend", "Green Triblend", "Red Triblend", "Wht Flck Triblnd"]
19
+
20
+ assert_equal expected, matching_shirts.first.colors
21
+ end
22
+
23
+ def test_a_product_knows_its_images
24
+ shirt = @products.select {|p| p.name == "Bella Sheer Triblend Racerback"}.first
25
+ expected = ["http://i1.ooshirts.com/images/lab_shirts/Charcoal-Triblend-212-F.jpg", "http://i1.ooshirts.com/images/lab_shirts/Charcoal-Triblend-212-B.jpg"]
26
+ assert_equal expected, shirt.images_for_color("Charcoal Triblend")
27
+ end
28
+
29
+ def test_a_product_raises_on_invalid_color
30
+ shirt = @products.select {|p| p.name == "Bella Sheer Triblend Racerback"}.first
31
+ err = assert_raises(RuntimeError) do
32
+ shirt.images_for_color("waldo")
33
+ end
34
+
35
+ assert_equal "waldo is invalid color selection for Charcoal Triblend, Emerald Triblend, Grey Triblend, Blue Triblend, Green Triblend, Red Triblend, Wht Flck Triblnd", err.message
36
+ end
37
+
38
+ def test_a_product_raises_on_no_images
39
+ #this test currently works because scalablepress is broken here
40
+ shirt = @products.select {|p| p.product_id == "next-level-racerback-terry-tank"}.first
41
+ err = assert_raises(RuntimeError) do
42
+ shirt.images_for_color("White")
43
+ end
44
+
45
+ assert_equal "Found no images for White!", err.message
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scalablepress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - oren mazor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-18 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: quick and dirty wrapper for the scalable press api
70
+ email:
71
+ - oren.mazor@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/scalablepress.rb
84
+ - lib/scalablepress/api.rb
85
+ - lib/scalablepress/resources/category.rb
86
+ - lib/scalablepress/resources/product.rb
87
+ - lib/scalablepress/version.rb
88
+ - scalablepress.gemspec
89
+ - tests/test_category.rb
90
+ - tests/test_helper.rb
91
+ - tests/test_product.rb
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: quick and dirty wrapper for the scalable press api
116
+ test_files: []