dawanda_client 0.1.9 → 0.1.10

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10
data/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ require "lib/dawanda.rb"
2
+ require "examples/shop/shop.rb"
3
+ run Sinatra::Application
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dawanda_client}
8
- s.version = "0.1.9"
8
+ s.version = "0.1.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["DaWanda GmbH"]
12
- s.date = %q{2010-03-09}
12
+ s.date = %q{2010-03-16}
13
13
  s.description = %q{Provides a friendly ruby-like interface to the Dawanda API}
14
14
  s.email = %q{api@dawanda.com}
15
15
  s.extra_rdoc_files = [
@@ -21,12 +21,14 @@ Gem::Specification.new do |s|
21
21
  "README.rdoc",
22
22
  "Rakefile",
23
23
  "VERSION",
24
+ "config.ru",
24
25
  "dawanda_client.gemspec",
25
26
  "lib/dawanda.rb",
26
27
  "lib/dawanda/category.rb",
27
28
  "lib/dawanda/channel.rb",
28
29
  "lib/dawanda/color.rb",
29
30
  "lib/dawanda/model.rb",
31
+ "lib/dawanda/pinboard.rb",
30
32
  "lib/dawanda/product.rb",
31
33
  "lib/dawanda/request.rb",
32
34
  "lib/dawanda/response.rb",
data/lib/dawanda/model.rb CHANGED
@@ -35,13 +35,17 @@ module Dawanda
35
35
  names.each {|name| attribute(name) }
36
36
  end
37
37
 
38
- def finder(type, endpoint)
39
- parameter = endpoint.scan(/:\w+/).first
40
- parameter.sub!(/^:/, '')
41
-
42
- endpoint.sub!(":#{parameter}", '#{' + parameter + '}')
43
-
44
- send("find_#{type}", parameter, endpoint)
38
+ def finder(type, endpoint, name=nil)
39
+ if name.nil?
40
+ parameter = endpoint.scan(/:\w+/).first
41
+ parameter.sub!(/^:/, '')
42
+
43
+ endpoint.sub!(":#{parameter}", '#{' + parameter + '}')
44
+
45
+ send("find_#{type}", parameter, endpoint)
46
+ elsif type == :generic
47
+ send("find_#{type}", name, endpoint)
48
+ end
45
49
  end
46
50
 
47
51
  def find_all(parameter, endpoint)
@@ -49,7 +53,7 @@ module Dawanda
49
53
  def self.find_all_by_#{parameter}(#{parameter}, params = {})
50
54
  response = Request.get("#{endpoint}", params.reject{|key, value| key == :raw_response})
51
55
  return response if params[:raw_response]
52
- response.result.map {|listing| new(listing) }
56
+ response.results.map {|listing| new(listing) }
53
57
  end
54
58
  CODE
55
59
  end
@@ -64,6 +68,19 @@ module Dawanda
64
68
  CODE
65
69
  end
66
70
 
71
+ def find_generic(name, endpoint)
72
+ class_eval <<-CODE
73
+ def self.find_#{name}(params = {})
74
+ response = Request.get("#{endpoint}", params.reject{|key, value| key == :raw_response})
75
+ return response if params[:raw_response]
76
+ if response.result.nil?
77
+ response.results.map {|listing| new(listing) }
78
+ else
79
+ new response.result
80
+ end
81
+ end
82
+ CODE
83
+ end
67
84
  end
68
85
 
69
86
  module InstanceMethods
@@ -0,0 +1,25 @@
1
+ module Dawanda
2
+
3
+ # = Pinboard
4
+ #
5
+ # Represents a Pinboard - has the following attributes:
6
+ #
7
+ # [id] The unique identifier for this pinboard
8
+ # [name] The pinboard's name
9
+ # [description] Pinboard's description
10
+ #
11
+ class Pinboard
12
+
13
+ include Dawanda::Model
14
+
15
+ finder :one, '/pinboards/:id'
16
+ finder :all, '/users/:user_id/pinboards'
17
+
18
+ attributes :id, :name, :description
19
+
20
+ def products(params = {})
21
+ Product.find_all_by_pinboard_id(id, params)
22
+ end
23
+
24
+ end
25
+ end
@@ -25,6 +25,8 @@ module Dawanda
25
25
  finder :all, '/colors/:hex/products'
26
26
  finder :all, '/colors/:hex_search/products/search'
27
27
  finder :all, '/product/:method'
28
+ finder :all, '/pinboards/:pinboard_id/products'
29
+ finder :generic, '/shops/window_products', :window_products_by_user_id
28
30
 
29
31
  finder :one, '/products/:id'
30
32
 
@@ -8,7 +8,7 @@ module Dawanda
8
8
 
9
9
  # The base URL for API requests
10
10
  def self.base_url
11
- url = "http://#{Dawanda.country}.dawanda.com/api/v1"
11
+ url = "http://#{Dawanda.country}.#{Dawanda.domain}/api/v1"
12
12
  end
13
13
 
14
14
  # Perform a GET request for the resource with optional parameters - returns
@@ -38,10 +38,14 @@ module Dawanda
38
38
  def params
39
39
  to_hash['params']
40
40
  end
41
- # Results of the API request
41
+ # Result of the API request that expect exactly one result
42
42
  def result
43
- entries == 1 ? to_hash['result'][type] : to_hash['result'].values.first
43
+ to_hash['result'][type]
44
44
  end
45
45
 
46
+ # Results of the API request that expect an arry of results
47
+ def results
48
+ to_hash['result'].values.first
49
+ end
46
50
  end
47
51
  end
data/lib/dawanda/shop.rb CHANGED
@@ -24,7 +24,7 @@ module Dawanda
24
24
  attribute :user_id, [:user, :id]
25
25
  attribute :banner_image_url, [:images, 0, :shop_banner]
26
26
 
27
- attributes :name
27
+ attributes :name, :description
28
28
 
29
29
  # Time that this shop was created
30
30
  #
@@ -48,6 +48,11 @@ module Dawanda
48
48
  find_all_by_method('shops')
49
49
  end
50
50
 
51
+ # shop_window_products
52
+ def shop_window_products
53
+ @shop_window_products ||= Product.find_window_products_by_user_id(:user_id => user_id)
54
+ end
55
+
51
56
  # A collection of products in this user's shop. See Dawanda::Product for
52
57
  # more information
53
58
  #
data/lib/dawanda/user.rb CHANGED
@@ -56,5 +56,9 @@ module Dawanda
56
56
  images.first['image_170x']
57
57
  end
58
58
 
59
+ def pinboards(params = {})
60
+ Pinboard.find_all_by_user_id(id, params)
61
+ end
62
+
59
63
  end
60
64
  end
data/lib/dawanda.rb CHANGED
@@ -15,6 +15,7 @@ require 'dawanda/category'
15
15
  require 'dawanda/shop_category'
16
16
  require 'dawanda/color'
17
17
  require 'dawanda/channel'
18
+ require 'dawanda/pinboard'
18
19
 
19
20
  # = DaWanda Client: A friendly Ruby interface to the DaWanda API
20
21
  #
@@ -71,6 +72,16 @@ module Dawanda
71
72
  @country || 'de'
72
73
  end
73
74
 
75
+ # Set the domain for all requests
76
+ def self.domain=(domain)
77
+ @domain = domain
78
+ end
79
+
80
+ # Retrieve the domain
81
+ def self.domain
82
+ @domain || 'dawanda.com'
83
+ end
84
+
74
85
  # Find a user by username. See Dawanda::User for more information.
75
86
  def self.user(username_or_id, options={})
76
87
  User.find_by_user_id(username_or_id, options)
@@ -96,4 +107,9 @@ module Dawanda
96
107
  ShopCategory.find_by_id(shop_category_id, options)
97
108
  end
98
109
 
110
+ # Find a pinboard by id. See Dawanda::Pinboard for more information.
111
+ def self.pinboard(pinboard_id)
112
+ Pinboard.find_by_id(pinboard_id)
113
+ end
114
+
99
115
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 9
9
- version: 0.1.9
8
+ - 10
9
+ version: 0.1.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - DaWanda GmbH
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-09 00:00:00 +01:00
17
+ date: 2010-03-16 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -32,12 +32,14 @@ files:
32
32
  - README.rdoc
33
33
  - Rakefile
34
34
  - VERSION
35
+ - config.ru
35
36
  - dawanda_client.gemspec
36
37
  - lib/dawanda.rb
37
38
  - lib/dawanda/category.rb
38
39
  - lib/dawanda/channel.rb
39
40
  - lib/dawanda/color.rb
40
41
  - lib/dawanda/model.rb
42
+ - lib/dawanda/pinboard.rb
41
43
  - lib/dawanda/product.rb
42
44
  - lib/dawanda/request.rb
43
45
  - lib/dawanda/response.rb