dawanda-dawanda_client 0.1.0
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/README.rdoc +72 -0
- data/Rakefile +38 -0
- data/lib/dawanda/model.rb +79 -0
- data/lib/dawanda/product.rb +62 -0
- data/lib/dawanda/request.rb +54 -0
- data/lib/dawanda/response.rb +47 -0
- data/lib/dawanda/shop.rb +52 -0
- data/lib/dawanda/user.rb +53 -0
- data/lib/dawanda.rb +88 -0
- data/test/fixtures/getShopDetails.json +67 -0
- data/test/test_helper.rb +49 -0
- data/test/unit/dawanda/shop_test.rb +63 -0
- metadata +79 -0
data/README.rdoc
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
= Dawanda
|
|
2
|
+
|
|
3
|
+
== Description
|
|
4
|
+
|
|
5
|
+
The Dawanda gem provides a friendly Ruby interface to the Dawanda API
|
|
6
|
+
|
|
7
|
+
== Installation
|
|
8
|
+
|
|
9
|
+
Installing the latest stable version is simple:
|
|
10
|
+
|
|
11
|
+
sudo gem install dawanda-dawanda_client --source=http://gems.github.com
|
|
12
|
+
|
|
13
|
+
== Usage
|
|
14
|
+
|
|
15
|
+
The Dawanda API is read-only - all you need to gain access is an API Key (available
|
|
16
|
+
from http://dawanda.com/apps). Once you have your API key, set it in your script:
|
|
17
|
+
|
|
18
|
+
require 'rubygems'
|
|
19
|
+
require 'dawanda'
|
|
20
|
+
Dawanda.api_key = 'foobar'
|
|
21
|
+
Dawanda.country = 'de'
|
|
22
|
+
|
|
23
|
+
From there, you can make any calls to the API that you need.
|
|
24
|
+
|
|
25
|
+
=== Users
|
|
26
|
+
|
|
27
|
+
If you're starting with a user, the easiest way is to use the Dawanda.user method:
|
|
28
|
+
|
|
29
|
+
>> user = Dawanda.user('meko')
|
|
30
|
+
=> #<Dawanda::User:0x141bf58 @result={"name"=>"meko", "city"=>"auma", "is_seller"=>true, ...
|
|
31
|
+
>> user.name
|
|
32
|
+
=> "meko"
|
|
33
|
+
>> user.id
|
|
34
|
+
=> 13008
|
|
35
|
+
|
|
36
|
+
For more information about what is available for a user, check out the documentation
|
|
37
|
+
for Dawanda::User.
|
|
38
|
+
|
|
39
|
+
== Shops
|
|
40
|
+
|
|
41
|
+
Each user may optionally have a shop. If a user is a seller, he / she also has an
|
|
42
|
+
associated shop object:
|
|
43
|
+
|
|
44
|
+
>> user.seller?
|
|
45
|
+
=> true
|
|
46
|
+
>> shop = user.shop
|
|
47
|
+
=> #<Dawanda::Shop:0x14170c0 @result={"is_vacation"=>false, "name"=>"MEKO STORE" ...
|
|
48
|
+
>> shop.name
|
|
49
|
+
=> "MEKO STORE"
|
|
50
|
+
|
|
51
|
+
More information about shops can be found in the documentation for Dawanda::Shop.
|
|
52
|
+
|
|
53
|
+
== Products
|
|
54
|
+
|
|
55
|
+
Shops contain multiple listings:
|
|
56
|
+
|
|
57
|
+
>> shop.products
|
|
58
|
+
=> [#<Dawanda::Product:0x1405f3c @result={"price"=>{"cents"=>2500, "currency_code"=>"EUR"}, "name"=>"Harmonie", ... ]
|
|
59
|
+
>> product = shop.products.first
|
|
60
|
+
=> #<Dawanda::Product:0x1405f3c @result={"price"=>{"cents"=>2500, "currency_code"=>"EUR"}, "name"=>"Harmonie", ...
|
|
61
|
+
>> product.name
|
|
62
|
+
=> "Harmonie"
|
|
63
|
+
>> listing.description
|
|
64
|
+
=> "Harmonie \n- Inselsymposium / Gimmlitztal \n- Eiche \n- geölt \n- L:150 / Durchmesser ca. 28cm"
|
|
65
|
+
>> listing.product_url
|
|
66
|
+
=> ""http://de.dawanda.com/product/1-Harmonie""
|
|
67
|
+
>> listing.view_count
|
|
68
|
+
=> 155
|
|
69
|
+
>> listing.created_at
|
|
70
|
+
=> Sat Sep 16 01:35:05 +0200 2006
|
|
71
|
+
|
|
72
|
+
See the documentation for Dawanda::Listing for more information.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake/gempackagetask'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
|
|
5
|
+
task :default => :test
|
|
6
|
+
|
|
7
|
+
spec = Gem::Specification.new do |s|
|
|
8
|
+
s.name = 'dawamda'
|
|
9
|
+
s.version = '0.1.0'
|
|
10
|
+
s.has_rdoc = true
|
|
11
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
|
12
|
+
s.rdoc_options = %w(--main README.rdoc)
|
|
13
|
+
s.summary = "Provides a friendly ruby-like interface to the Dawanda API"
|
|
14
|
+
s.author = 'Christoph Bünte'
|
|
15
|
+
s.email = 'info@christophbuente.de'
|
|
16
|
+
s.homepage = 'http://www.christophbuente.de'
|
|
17
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
|
18
|
+
# s.executables = ['dawanda']
|
|
19
|
+
|
|
20
|
+
s.add_dependency('json', '~> 1.1.0')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
|
24
|
+
pkg.gem_spec = spec
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Rake::TestTask.new do |t|
|
|
28
|
+
t.libs << 'test'
|
|
29
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
30
|
+
t.verbose = true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
desc 'Generate the gemspec to serve this Gem from Github'
|
|
34
|
+
task :github do
|
|
35
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
|
36
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
|
37
|
+
puts "Created gemspec: #{file}"
|
|
38
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module Dawanda
|
|
2
|
+
module Model # :nodoc:all
|
|
3
|
+
|
|
4
|
+
module ClassMethods
|
|
5
|
+
|
|
6
|
+
def attribute(name, options = {})
|
|
7
|
+
from = parse_from(name,options)
|
|
8
|
+
if from.is_a? Array
|
|
9
|
+
class_eval <<-CODE
|
|
10
|
+
def #{name}
|
|
11
|
+
@result['#{from.first}']['#{from.last}']
|
|
12
|
+
end
|
|
13
|
+
CODE
|
|
14
|
+
else
|
|
15
|
+
class_eval <<-CODE
|
|
16
|
+
def #{name}
|
|
17
|
+
@result['#{from}']
|
|
18
|
+
end
|
|
19
|
+
CODE
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def parse_from(name,options)
|
|
24
|
+
from = options.fetch(:from,name)
|
|
25
|
+
return from unless from.is_a? Hash
|
|
26
|
+
key = from.keys.first
|
|
27
|
+
value = from.fetch(key)
|
|
28
|
+
[key,value]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def attributes(*names)
|
|
32
|
+
names.each {|name| attribute(name) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def finder(type, endpoint)
|
|
36
|
+
parameter = endpoint.scan(/:\w+/).first
|
|
37
|
+
parameter.sub!(/^:/, '')
|
|
38
|
+
|
|
39
|
+
endpoint.sub!(":#{parameter}", '#{' + parameter + '}')
|
|
40
|
+
|
|
41
|
+
send("find_#{type}", parameter, endpoint)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def find_all(parameter, endpoint)
|
|
45
|
+
class_eval <<-CODE
|
|
46
|
+
def self.find_all_by_#{parameter}(#{parameter})
|
|
47
|
+
response = Request.get("#{endpoint}")
|
|
48
|
+
response.result.map {|listing| new(listing) }
|
|
49
|
+
end
|
|
50
|
+
CODE
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def find_one(parameter, endpoint)
|
|
54
|
+
class_eval <<-CODE
|
|
55
|
+
def self.find_by_#{parameter}(#{parameter})
|
|
56
|
+
response = Request.get("#{endpoint}")
|
|
57
|
+
new response.result
|
|
58
|
+
end
|
|
59
|
+
CODE
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
module InstanceMethods
|
|
65
|
+
|
|
66
|
+
def initialize(result = nil)
|
|
67
|
+
@result = result
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.included(other)
|
|
73
|
+
other.send(:extend, Dawanda::Model::ClassMethods)
|
|
74
|
+
other.send(:include, Dawanda::Model::InstanceMethods)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Dawanda
|
|
2
|
+
|
|
3
|
+
# = Listing
|
|
4
|
+
#
|
|
5
|
+
# Represents a single Dawanda product. Has the following attributes:
|
|
6
|
+
#
|
|
7
|
+
# [id] The unique identifier for this listing
|
|
8
|
+
# [title] The title of this listing
|
|
9
|
+
# [description] This listing's full description
|
|
10
|
+
# [view_count] The number of times this listing has been viewed
|
|
11
|
+
# [url] The full URL to this listing's detail page
|
|
12
|
+
# [price] The price of this listing item
|
|
13
|
+
# [currency] The currency that the seller is using for this listing item
|
|
14
|
+
# [quantity] The number of items available for sale
|
|
15
|
+
# [tags] An array of tags that the seller has used for this listing
|
|
16
|
+
# [materials] Any array of materials that was used in the production of this item
|
|
17
|
+
#
|
|
18
|
+
# Additionally, the following queries on this item are available:
|
|
19
|
+
#
|
|
20
|
+
# [active?] Is this listing active?
|
|
21
|
+
# [removed?] Has this listing been removed?
|
|
22
|
+
# [sold_out?] Is this listing sold out?
|
|
23
|
+
# [expired?] Has this listing expired?
|
|
24
|
+
# [alchemy?] Is this listing an Alchemy item? (i.e. requested by an Dawanda user)
|
|
25
|
+
#
|
|
26
|
+
class Product
|
|
27
|
+
|
|
28
|
+
include Dawanda::Model
|
|
29
|
+
|
|
30
|
+
finder :all, '/shops/:shop_id/products'
|
|
31
|
+
finder :all, '/categories/:category_id/products'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
finder :one, '/products/:product_id'
|
|
35
|
+
|
|
36
|
+
attribute :created, :from => :created_at
|
|
37
|
+
|
|
38
|
+
attributes :id, :name, :description, :created_at, :view_count, :tags,
|
|
39
|
+
:ending, :quantity, :materials, :price, :restful_path, :product_url, :images
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# Time that this listing was created
|
|
43
|
+
#
|
|
44
|
+
def created_at
|
|
45
|
+
Time.parse(created)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Time that this listing is ending (will be removed from store)
|
|
49
|
+
#
|
|
50
|
+
def ending_at
|
|
51
|
+
Time.parse(ending)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# The primary image for this listing. See Dawanda::Image for more
|
|
55
|
+
# information
|
|
56
|
+
#
|
|
57
|
+
def image_25x25
|
|
58
|
+
images.first['image_25x25']
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module Dawanda
|
|
2
|
+
|
|
3
|
+
# = Request
|
|
4
|
+
#
|
|
5
|
+
# A basic wrapper around GET requests to the Dawanda JSON API
|
|
6
|
+
#
|
|
7
|
+
class Request
|
|
8
|
+
|
|
9
|
+
# The base URL for API requests
|
|
10
|
+
def self.base_url
|
|
11
|
+
url = "http://#{Dawanda.country}.devanda.com/api/v1"
|
|
12
|
+
puts url
|
|
13
|
+
url
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Perform a GET request for the resource with optional parameters - returns
|
|
17
|
+
# A Response object with the payload data
|
|
18
|
+
def self.get(resource_path, parameters = {})
|
|
19
|
+
parameters = {:format => 'json'}.update(parameters)
|
|
20
|
+
request = Request.new(resource_path, parameters)
|
|
21
|
+
puts request.inspect
|
|
22
|
+
response = Response.new(request.get)
|
|
23
|
+
puts response.inspect
|
|
24
|
+
response
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Create a new request for the resource with optional parameters
|
|
28
|
+
def initialize(resource_path, parameters = {})
|
|
29
|
+
@resource_path = resource_path
|
|
30
|
+
@parameters = parameters
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Perform a GET request against the API endpoint and return the raw
|
|
34
|
+
# response data
|
|
35
|
+
def get
|
|
36
|
+
Net::HTTP.get(endpoint_uri)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def parameters # :nodoc:
|
|
40
|
+
@parameters.merge(:api_key => Dawanda.api_key)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def query # :nodoc:
|
|
44
|
+
parameters.map {|k,v| "#{k}=#{v}"}.join('&')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def endpoint_uri # :nodoc:
|
|
48
|
+
uri = URI.parse("#{self.class.base_url}#{@resource_path}")
|
|
49
|
+
uri.query = query
|
|
50
|
+
uri
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Dawanda
|
|
2
|
+
|
|
3
|
+
# = Response
|
|
4
|
+
#
|
|
5
|
+
# Basic wrapper around the Dawanda JSON response data
|
|
6
|
+
#
|
|
7
|
+
class Response
|
|
8
|
+
|
|
9
|
+
# Create a new response based on the raw JSON
|
|
10
|
+
def initialize(data)
|
|
11
|
+
@data = data
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Convert the raw JSON data to a hash
|
|
15
|
+
def to_hash
|
|
16
|
+
@hash ||= JSON.parse(@data)
|
|
17
|
+
@hash['response']
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Number of records in the response
|
|
21
|
+
def entries
|
|
22
|
+
to_hash['entries']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Number of pages in the response
|
|
26
|
+
def pages
|
|
27
|
+
to_hash['pages']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def type
|
|
31
|
+
to_hash['type']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def pluralized_type
|
|
35
|
+
type.to_s.pluralize
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def params
|
|
39
|
+
to_hash['params']
|
|
40
|
+
end
|
|
41
|
+
# Results of the API request
|
|
42
|
+
def result
|
|
43
|
+
entries == 1 ? to_hash['result'][type] : to_hash['result'].values.first
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/dawanda/shop.rb
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Dawanda
|
|
2
|
+
|
|
3
|
+
# = Shop
|
|
4
|
+
#
|
|
5
|
+
# Represents a single Dawanda shop. Users may or may not have an associated shop -
|
|
6
|
+
# check the result of User#seller? to find out.
|
|
7
|
+
#
|
|
8
|
+
# A shop has the following attributes:
|
|
9
|
+
#
|
|
10
|
+
# [name] The shop's name
|
|
11
|
+
# [title] A brief heading for the shop's main page
|
|
12
|
+
# [announcement] An announcement to buyers (displays on the shop's home page)
|
|
13
|
+
# [message] The message sent to users who buy from this shop
|
|
14
|
+
# [banner_image_url] The full URL to the shops's banner image
|
|
15
|
+
# [listing_count] The total number of active listings contained in this shop
|
|
16
|
+
#
|
|
17
|
+
class Shop
|
|
18
|
+
|
|
19
|
+
include Dawanda::Model
|
|
20
|
+
|
|
21
|
+
finder :one, '/shops/:user_id'
|
|
22
|
+
|
|
23
|
+
attribute :updated, :from => :updated_at
|
|
24
|
+
attribute :created, :from => :created_at
|
|
25
|
+
attribute :user_id, :from => {:user => :id }
|
|
26
|
+
|
|
27
|
+
attributes :banner_image_url, :listing_count, :title, :announcement, :name
|
|
28
|
+
|
|
29
|
+
# Time that this shop was created
|
|
30
|
+
#
|
|
31
|
+
def created_at
|
|
32
|
+
Time.parse(created)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Time that this shop was last updated
|
|
36
|
+
#
|
|
37
|
+
def updated_at
|
|
38
|
+
Time.parse(updated)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# A collection of listings in this user's shop. See Dawanda::Listing for
|
|
42
|
+
# more information
|
|
43
|
+
#
|
|
44
|
+
def products
|
|
45
|
+
@products ||= Product.find_all_by_shop_id(user_id.to_s)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def user
|
|
49
|
+
@user ||= User.find_by_user_id(user_id)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/dawanda/user.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Dawanda
|
|
2
|
+
|
|
3
|
+
# = User
|
|
4
|
+
#
|
|
5
|
+
# Represents a single Dawanda user - has the following attributes:
|
|
6
|
+
#
|
|
7
|
+
# [id] The unique identifier for this user
|
|
8
|
+
# [name] This user's username
|
|
9
|
+
# [city] The user's city / state (optional)
|
|
10
|
+
# [sex] The user's gender
|
|
11
|
+
# [transaction_sold_count] How many products have been sold by this user
|
|
12
|
+
# [is_seller] Is this user a seller?
|
|
13
|
+
# [bio] User's biography
|
|
14
|
+
# [restful_path]
|
|
15
|
+
# [url] The full URL to this user's profile page / shop (if seller)
|
|
16
|
+
#
|
|
17
|
+
class User
|
|
18
|
+
|
|
19
|
+
include Dawanda::Model
|
|
20
|
+
|
|
21
|
+
finder :one, '/users/:user_id'
|
|
22
|
+
|
|
23
|
+
# attribute :last_login, :from => :last_login_epoch
|
|
24
|
+
|
|
25
|
+
attributes :id, :name, :url, :city, :sex, :bio, :transaction_sold_count, :is_seller, :images
|
|
26
|
+
|
|
27
|
+
# This user's shop, returns nil if user is not a seller. See Dawanda::Shop
|
|
28
|
+
# for more information.
|
|
29
|
+
#
|
|
30
|
+
def shop
|
|
31
|
+
@shop ||= Shop.find_by_user_id(id) if seller?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Is this user a seller?
|
|
35
|
+
#
|
|
36
|
+
def seller?
|
|
37
|
+
is_seller
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def image_40x40
|
|
41
|
+
images.first['image_40x40']
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def image_80x80
|
|
45
|
+
images.first['image_80x80']
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def image_170x
|
|
49
|
+
images.first['image_170x']
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
data/lib/dawanda.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'time'
|
|
6
|
+
|
|
7
|
+
require 'dawanda/request'
|
|
8
|
+
require 'dawanda/response'
|
|
9
|
+
|
|
10
|
+
require 'dawanda/model'
|
|
11
|
+
require 'dawanda/user'
|
|
12
|
+
require 'dawanda/shop'
|
|
13
|
+
require 'dawanda/product'
|
|
14
|
+
require 'dawanda/category'
|
|
15
|
+
|
|
16
|
+
# = DaWanda Client: A friendly Ruby interface to the DaWanda API
|
|
17
|
+
#
|
|
18
|
+
# == Quick Start
|
|
19
|
+
#
|
|
20
|
+
# Getting started is easy. First, you will need a valid API key from the Dawanda
|
|
21
|
+
# developer site (http://developer.dawanda.com/). Since the API is read-only at
|
|
22
|
+
# the moment, that's all you need to do.
|
|
23
|
+
#
|
|
24
|
+
# To start using the API, require the dawanda gem and set it up to use your API key:
|
|
25
|
+
#
|
|
26
|
+
# require 'rubygems'
|
|
27
|
+
# require 'dawanda_client'
|
|
28
|
+
#
|
|
29
|
+
# Dawanda.api_key = 'itsasecret'
|
|
30
|
+
#
|
|
31
|
+
# Now you can make API calls that originate from an Dawanda user:
|
|
32
|
+
#
|
|
33
|
+
# # Find a user by username
|
|
34
|
+
# user = Dawanda.user('littletjane')
|
|
35
|
+
#
|
|
36
|
+
# # Grab that user's shop information
|
|
37
|
+
# user.seller?
|
|
38
|
+
# user.shop
|
|
39
|
+
# user.shop.title
|
|
40
|
+
#
|
|
41
|
+
# # ... and the listings in the shop
|
|
42
|
+
# product = user.shop.products.first
|
|
43
|
+
# product.title
|
|
44
|
+
# product.description
|
|
45
|
+
#
|
|
46
|
+
# To see what else is available for a user, check out the full documentation for
|
|
47
|
+
# the Dawanda::User class.
|
|
48
|
+
#
|
|
49
|
+
module Dawanda
|
|
50
|
+
|
|
51
|
+
# Set the API key for all requests
|
|
52
|
+
def self.api_key=(api_key)
|
|
53
|
+
@api_key = api_key
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Retrieve the API key
|
|
57
|
+
def self.api_key
|
|
58
|
+
@api_key
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Set the country for all requests
|
|
62
|
+
def self.country=(country)
|
|
63
|
+
@country = country
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Retrieve the country
|
|
67
|
+
def self.country
|
|
68
|
+
@country || 'de'
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Find a user by username. See Dawanda::User for more information.
|
|
72
|
+
def self.user(username)
|
|
73
|
+
User.find_by_user_id(username)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.shop(username)
|
|
77
|
+
Shop.find_by_user_id(username)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.product(product_id)
|
|
81
|
+
Product.find_by_product_id(product_id)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.category(category_id)
|
|
85
|
+
Category.find_by_category_id(category_id)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"count": 1,
|
|
3
|
+
"results": [{
|
|
4
|
+
"user_name": "littletjane",
|
|
5
|
+
"user_id": 5327518,
|
|
6
|
+
"url": "http:\/\/de.dawanda.com\/shops/5327518",
|
|
7
|
+
"image_url_25x25": "http:\/\/img.dawanda.com\/User/806\/806038\/full\/5874999.jpg",
|
|
8
|
+
"join_epoch": 1191381757.93,
|
|
9
|
+
"city": "Washington, DC",
|
|
10
|
+
"gender": "female",
|
|
11
|
+
"lat": null,
|
|
12
|
+
"lon": null,
|
|
13
|
+
"transaction_buy_count": 199,
|
|
14
|
+
"transaction_sold_count": 0,
|
|
15
|
+
"is_seller": true,
|
|
16
|
+
"was_featured_seller": false,
|
|
17
|
+
"materials": ["paper", "pen_and_pencil", "crayon_and_coloring_books", "ink_and_stamps", "collage", "decoupage_medium", "paint_and_canvas", "stickers", "magnets", "fabric_and_plush", "toys", "vintage_and_found_objects", "ecofriendly_and_recycled_goods"],
|
|
18
|
+
"last_login_epoch": 1239797927.39,
|
|
19
|
+
"feedback_count": "171",
|
|
20
|
+
"feedback_percent_positive": "100",
|
|
21
|
+
"referred_user_count": 1,
|
|
22
|
+
"birth_day": "20",
|
|
23
|
+
"birth_month": "3",
|
|
24
|
+
"bio": "hello! :D \r\n\r\n:about me:\r\n\r\nBA, dance \r\ncertified massage therapist\r\nwife & stay-at-home mama to 3 little ones\r\n\r\n:love love love:\r\n\r\nmy family\r\nmy children's drawings\r\nmy dear friends\r\nmusic \r\ndance!\r\nyoga\r\narts & craftiness!\r\nbaking\r\nmy mac\r\ndreaming\r\nlaughing\r\nplaying\r\nreading\r\ncute happy things\r\n=^..^=\r\n\r\nhttp:\/\/littletjane.com\r\nplease say hi!\r\n\r\ni'm flip...hip...zappy zowie zip!",
|
|
25
|
+
"banner_image_url": "http:\/\/img.dawanda.com\/Shop/806\/806038\/full\/5874999.jpg",
|
|
26
|
+
"last_updated_epoch": 1239717723.36,
|
|
27
|
+
"creation_epoch": 1237430331.15,
|
|
28
|
+
"listing_count": 13,
|
|
29
|
+
"shop_name": "littletjane",
|
|
30
|
+
"title": "title text",
|
|
31
|
+
"sale_message": "message text",
|
|
32
|
+
"announcement": "announcement text",
|
|
33
|
+
"is_vacation": "",
|
|
34
|
+
"vacation_message": "",
|
|
35
|
+
"currency_code": "USD",
|
|
36
|
+
"policy_welcome": "oh hi! i'm so glad you've come by my shop! thank you so much for swinging in and taking a peek around :D\r\n\r\nwell, here are the 'ol policy-os. please do read carefully:",
|
|
37
|
+
"policy_payment": "payment method accepted: \r\npaypal (hooray!)\r\n\r\nterms: \r\nsubmit payment promptly. payment is due 3 days after purchase of the item. \r\n\r\nupon receipt of payment, the order will be shipped within 1 week.",
|
|
38
|
+
"policy_shipping": "method: usps first-class mail.\r\n \r\nplease feel free to contact me for rates on expedited shipping. \r\n\r\ni am not responsible for taxes or duties for your country.",
|
|
39
|
+
"policy_refunds": "oh help!\r\nif you are not happy with your item, please let me know. we can work this out! i will try my best to replace the item or refund your money, as the goal of my shop is to create and share in crafty happiness. right on!",
|
|
40
|
+
"policy_additional": "ok. well, that's about it! mostly, just be good, nice, honest, and fair, and this will return to you tenfold.\r\n\r\nif you have any questions, please don't hesitate to ask me.\r\n\r\nthanks a bunch, you! cheers!",
|
|
41
|
+
"sections": [{
|
|
42
|
+
"section_id": 6008529,
|
|
43
|
+
"title": "matchboxes",
|
|
44
|
+
"listing_count": 3
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"section_id": 6008530,
|
|
48
|
+
"title": "original paintings",
|
|
49
|
+
"listing_count": 3
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"section_id": 6059955,
|
|
53
|
+
"title": "sachets",
|
|
54
|
+
"listing_count": 5
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"section_id": 6061498,
|
|
58
|
+
"title": "hand carved stamps",
|
|
59
|
+
"listing_count": 2
|
|
60
|
+
}]
|
|
61
|
+
}],
|
|
62
|
+
"params": {
|
|
63
|
+
"user_id": 5327518,
|
|
64
|
+
"detail_level": "high"
|
|
65
|
+
},
|
|
66
|
+
"type": "shop"
|
|
67
|
+
}
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# http://sneaq.net/textmate-wtf
|
|
2
|
+
$:.reject! { |e| e.include? 'TextMate' }
|
|
3
|
+
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'throat_punch'
|
|
6
|
+
|
|
7
|
+
require File.dirname(__FILE__) + '/../lib/dawanda'
|
|
8
|
+
|
|
9
|
+
class Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
def self.read_fixture(method_name)
|
|
12
|
+
file = File.dirname(__FILE__) + "/fixtures/#{method_name}.json"
|
|
13
|
+
JSON.parse(File.read(file))['results']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def read_fixture(method_name)
|
|
17
|
+
self.class.read_fixture(method_name)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def mock_request_cycle(options)
|
|
21
|
+
response = Dawanda::Response.new(stub())
|
|
22
|
+
|
|
23
|
+
data = read_fixture(options[:data])
|
|
24
|
+
data = data.first if data.size == 1
|
|
25
|
+
|
|
26
|
+
response.stubs(:result).with().returns(data)
|
|
27
|
+
|
|
28
|
+
Dawanda::Request.stubs(:get).with(options[:for]).returns(response)
|
|
29
|
+
|
|
30
|
+
response
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.when_populating(klass, options, &block)
|
|
34
|
+
data = options[:from].is_a?(String) ? read_fixture(options[:from])[0] : options[:from].call
|
|
35
|
+
|
|
36
|
+
context "with data populated for #{klass}" do
|
|
37
|
+
setup { @object = klass.new(data) }
|
|
38
|
+
merge_block(&block)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.value_for(method_name, options)
|
|
44
|
+
should "have a value for :#{method_name}" do
|
|
45
|
+
@object.send(method_name).should == options[:is]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
|
2
|
+
|
|
3
|
+
module Dawanda
|
|
4
|
+
class ShopTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
context "The Shop class" do
|
|
7
|
+
|
|
8
|
+
should "be able to find a shop by :user_id" do
|
|
9
|
+
user_id = 5327518
|
|
10
|
+
response = mock_request_cycle :for => "/shops/#{user_id}", :data => 'getShopDetails'
|
|
11
|
+
|
|
12
|
+
Shop.expects(:new).with(response.result).returns('shop')
|
|
13
|
+
|
|
14
|
+
Shop.find_by_user_id(user_id).should == 'shop'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "An instance of the Shop class" do
|
|
20
|
+
|
|
21
|
+
when_populating Shop, :from => 'getShopDetails' do
|
|
22
|
+
|
|
23
|
+
value_for :user_id, :is => 5327518
|
|
24
|
+
value_for :banner_image_url, :is => "http://img.dawanda.com/Shop/806/806038/full/5874999.jpg",
|
|
25
|
+
value_for :products_count, :is => 13
|
|
26
|
+
value_for :updated_at, :is => 1239717723.36
|
|
27
|
+
value_for :created_at, :is => 1237430331.15
|
|
28
|
+
value_for :name, :is => 'littletjane'
|
|
29
|
+
value_for :title, :is => 'title text'
|
|
30
|
+
value_for :message, :is => 'message text'
|
|
31
|
+
value_for :announcement, :is => 'announcement text'
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should "know the creation date" do
|
|
36
|
+
shop = Shop.new
|
|
37
|
+
shop.stubs(:created_at).with().returns(Time.at(1237430331.15))
|
|
38
|
+
|
|
39
|
+
shop.created_at.should == Time.at(1237430331.15)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
should "know the update date" do
|
|
43
|
+
shop = Shop.new
|
|
44
|
+
shop.stubs(:updated_at).with().returns(Time.at(1239717723.36))
|
|
45
|
+
|
|
46
|
+
shop.updated_at.should == Time.at(1239717723.36)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
should "have a collection of products" do
|
|
50
|
+
user_id = 123
|
|
51
|
+
|
|
52
|
+
shop = Shop.new
|
|
53
|
+
shop.expects(:user_id).with().returns(user_id)
|
|
54
|
+
|
|
55
|
+
Product.expects(:find_all_by_user_id).with(user_id).returns('products')
|
|
56
|
+
|
|
57
|
+
shop.products.should == 'products'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dawanda-dawanda_client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "Christoph B\xC3\xBCnte"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-09-17 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: json
|
|
17
|
+
type: :runtime
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ~>
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 1.1.0
|
|
24
|
+
version:
|
|
25
|
+
description:
|
|
26
|
+
email: info@christophbuente.de
|
|
27
|
+
executables: []
|
|
28
|
+
|
|
29
|
+
extensions: []
|
|
30
|
+
|
|
31
|
+
extra_rdoc_files:
|
|
32
|
+
- README.rdoc
|
|
33
|
+
files:
|
|
34
|
+
- README.rdoc
|
|
35
|
+
- Rakefile
|
|
36
|
+
- lib/dawanda
|
|
37
|
+
- lib/dawanda/product.rb
|
|
38
|
+
- lib/dawanda/model.rb
|
|
39
|
+
- lib/dawanda/request.rb
|
|
40
|
+
- lib/dawanda/response.rb
|
|
41
|
+
- lib/dawanda/shop.rb
|
|
42
|
+
- lib/dawanda/user.rb
|
|
43
|
+
- lib/dawanda.rb
|
|
44
|
+
- test/fixtures
|
|
45
|
+
- test/fixtures/getShopDetails.json
|
|
46
|
+
- test/test_helper.rb
|
|
47
|
+
- test/unit
|
|
48
|
+
- test/unit/dawanda
|
|
49
|
+
- test/unit/dawanda/shop_test.rb
|
|
50
|
+
has_rdoc: true
|
|
51
|
+
homepage: http://sneaq.net
|
|
52
|
+
licenses:
|
|
53
|
+
post_install_message:
|
|
54
|
+
rdoc_options:
|
|
55
|
+
- --main
|
|
56
|
+
- README.rdoc
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: "0"
|
|
64
|
+
version:
|
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: "0"
|
|
70
|
+
version:
|
|
71
|
+
requirements: []
|
|
72
|
+
|
|
73
|
+
rubyforge_project:
|
|
74
|
+
rubygems_version: 1.3.5
|
|
75
|
+
signing_key:
|
|
76
|
+
specification_version: 2
|
|
77
|
+
summary: Provides a friendly ruby-like interface to the DaWanda API
|
|
78
|
+
test_files: []
|
|
79
|
+
|