svpply 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@svpply-gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in svpply.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jeff Mehlhoff
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.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Svpply
2
+
3
+ This is a ruby wrapper for the Svpply API. It's a work in progress.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'svpply'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install svpply
18
+
19
+ ## Usage
20
+
21
+ ### Products
22
+
23
+ To return all products in the "Shop" section:
24
+
25
+ $ Svpply.products
26
+
27
+ To perform a search, the syntax is similar:
28
+
29
+ $ Svpply.products("tshirt")
30
+ $ Svpply.products("tshirt", genders: ['male'], prices: ['$1-20'])
31
+ $ Svpply.products(genders: ['male'])
32
+
33
+ etc...
34
+
35
+ Single product lookup:
36
+
37
+ $ Svpply.product(880581)
38
+
39
+
40
+ ### Categories
41
+
42
+ Return all categories:
43
+
44
+ $ Svpply.categories
45
+
46
+ Products in a given category:
47
+
48
+ $ Svpply.categories.first.products
49
+
50
+ Categories have children categories:
51
+
52
+ $ Svpply.categories.first.children
53
+ $ Svpply.categories.first.children.first.products
54
+
55
+ etc...
56
+
57
+
58
+ ## TODO:
59
+
60
+ 1. Tests
61
+ 2. Refactor
62
+ 3. Flush out full API
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
Binary file
@@ -0,0 +1,22 @@
1
+ module Svpply
2
+ class Category
3
+ attr_reader :name, :url, :children, :api_url
4
+
5
+ def self.all
6
+ CategoryCollection.new(Client.get_response('/shop/categories.json')).categories
7
+ end
8
+
9
+ def initialize(hash)
10
+ @name = hash["name"]
11
+ @url = hash["url"]
12
+ @children = hash["children"].nil? ? [] : hash["children"].map { |c| Category.new(c) }
13
+ @api_url = @url[25, 1000]
14
+ self
15
+ end
16
+
17
+ def products(attrs=nil)
18
+ ProductCollection.new(Client.get_response(@api_url, attrs)).products
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module Svpply
2
+ class CategoryCollection
3
+ attr_reader :categories
4
+
5
+ def initialize(response)
6
+ @categories = response["categories"][0]["children"].map { |c| Category.new(c) }
7
+ self
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,30 @@
1
+ module Svpply
2
+ module Client
3
+ include HTTParty
4
+ base_uri "https://api.svpply.com/v1"
5
+
6
+ def self.get_response(url, attrs=nil)
7
+ params = attrs ? prune_attributes(attrs) : {}
8
+ get(url, query: params)["response"]
9
+ end
10
+
11
+ private
12
+ def self.prune_attributes(attributes)
13
+ query = attributes.first if attributes.first.is_a?(String)
14
+ params = attributes.last.is_a?(Hash) ? attributes.last : {}
15
+ if params
16
+ params[:filters] = {}
17
+ if params[:genders]
18
+ genders = params.delete(:genders)
19
+ params[:filters][:genders] = [genders].flatten
20
+ end
21
+ if params[:prices]
22
+ prices = params.delete(:prices)
23
+ params[:filters][:prices] = [prices].flatten
24
+ end
25
+ end
26
+ return params.merge!({ q: query })
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ module Svpply
2
+ class Product
3
+ attr_reader :title, :price, :category, :gender, :image,
4
+ :image_height, :image_width, :id, :saves, :notes, :url, :svpply_url
5
+
6
+ def self.products(attrs=nil)
7
+ unless attrs.empty?
8
+ ProductCollection.new(Client.get_response('/products/search.json', attrs)).products
9
+ else
10
+ ProductCollection.new(Client.get_response('/shop.json')).products
11
+ end
12
+ end
13
+
14
+ def self.find(id)
15
+ new(Client.get_response("/products/#{id}.json")["product"])
16
+ end
17
+
18
+ def initialize(hash)
19
+ @title = hash["page_title"]
20
+ @price = hash["price"]
21
+ @category = hash["category"]
22
+ @gender = hash["gender"]
23
+ @image = hash["image"]
24
+ @image_width = hash["image_width"]
25
+ @image_height = hash["image_height"]
26
+ @id = hash["id"]
27
+ @saves = hash["saves"]
28
+ @notes = hash["notes"]
29
+ @url = hash["page_url"]
30
+ @svpply_url = "https://svpply.com/item/#{@id}"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ module Svpply
2
+ class ProductCollection
3
+ attr_reader :products_count, :products
4
+
5
+ def initialize(response)
6
+ @products = response["products"].map { |p| Product.new(p) }
7
+ @products_count = response["products_count"]
8
+ self
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Svpply
2
+ VERSION = "0.0.1.alpha"
3
+ end
data/lib/svpply.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'httparty'
2
+ require "svpply/version"
3
+ require "svpply/client"
4
+ require "svpply/product"
5
+ require "svpply/product_collection"
6
+ require "svpply/category"
7
+ require "svpply/category_collection"
8
+
9
+ module Svpply
10
+ def self.products(*attributes)
11
+ Product.products(attributes)
12
+ end
13
+
14
+ def self.product(id)
15
+ Product.find(id)
16
+ end
17
+
18
+ def self.categories
19
+ Category.all
20
+ end
21
+
22
+ end
@@ -0,0 +1,8 @@
1
+ require 'svpply'
2
+ require 'webmock'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'spec/fixtures'
7
+ c.hook_into :webmock
8
+ end
data/svpply.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/svpply/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jeff Mehlhoff"]
6
+ gem.email = ["jeffmehlhoff@mac.com"]
7
+ gem.description = %q{Ruby wrapper for the Svpply api}
8
+ gem.summary = %q{}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "svpply"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Svpply::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+ gem.add_development_dependency "webmock"
20
+ gem.add_development_dependency "vcr"
21
+ gem.add_runtime_dependency "httparty"
22
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svpply
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Mehlhoff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-10 00:00:00.000000000 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &70099416888440 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70099416888440
26
+ - !ruby/object:Gem::Dependency
27
+ name: webmock
28
+ requirement: &70099416888020 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70099416888020
37
+ - !ruby/object:Gem::Dependency
38
+ name: vcr
39
+ requirement: &70099416887600 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70099416887600
48
+ - !ruby/object:Gem::Dependency
49
+ name: httparty
50
+ requirement: &70099416887180 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *70099416887180
59
+ description: Ruby wrapper for the Svpply api
60
+ email:
61
+ - jeffmehlhoff@mac.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .rspec
68
+ - .rvmrc
69
+ - Gemfile
70
+ - LICENSE
71
+ - README.md
72
+ - Rakefile
73
+ - lib/svpply.rb
74
+ - lib/svpply/.DS_Store
75
+ - lib/svpply/category.rb
76
+ - lib/svpply/category_collection.rb
77
+ - lib/svpply/client.rb
78
+ - lib/svpply/product.rb
79
+ - lib/svpply/product_collection.rb
80
+ - lib/svpply/version.rb
81
+ - spec/spec_helper.rb
82
+ - svpply.gemspec
83
+ has_rdoc: true
84
+ homepage: ''
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>'
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.1
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.6.2
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: ''
108
+ test_files:
109
+ - spec/spec_helper.rb