etsy 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.
@@ -0,0 +1,30 @@
1
+ module Etsy
2
+
3
+ # = Response
4
+ #
5
+ # Basic wrapper around the Etsy 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
+ end
18
+
19
+ # Number of records in the response results
20
+ def count
21
+ to_hash['count']
22
+ end
23
+
24
+ # Results of the API request
25
+ def result
26
+ count == 1 ? to_hash['results'].first : to_hash['results']
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ module Etsy
2
+
3
+ # = Shop
4
+ #
5
+ # Represents a single Etsy 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 Etsy::Model
20
+
21
+ finder :one, '/shops/:user_id'
22
+
23
+ attribute :name, :from => :shop_name
24
+ attribute :updated, :from => :last_updated_epoch
25
+ attribute :created, :from => :creation_epoch
26
+ attribute :message, :from => :sale_message
27
+
28
+ attributes :banner_image_url, :listing_count, :title, :announcement, :user_id
29
+
30
+ # Time that this shop was created
31
+ #
32
+ def created_at
33
+ Time.at(created)
34
+ end
35
+
36
+ # Time that this shop was last updated
37
+ #
38
+ def updated_at
39
+ Time.at(updated)
40
+ end
41
+
42
+ # A collection of listings in this user's shop. See Etsy::Listing for
43
+ # more information
44
+ #
45
+ def listings
46
+ Listing.find_all_by_user_id(user_id)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,54 @@
1
+ module Etsy
2
+
3
+ # = User
4
+ #
5
+ # Represents a single Etsy user - has the following attributes:
6
+ #
7
+ # [id] The unique identifier for this user
8
+ # [username] This user's username
9
+ # [url] The full URL to this user's profile page / shop (if seller)
10
+ # [city] The user's city / state (optional)
11
+ # [gender] The user's gender
12
+ # [bio] User's biography
13
+ #
14
+ class User
15
+
16
+ include Etsy::Model
17
+
18
+ finder :one, '/users/:username'
19
+
20
+ attribute :username, :from => :user_name
21
+ attribute :id, :from => :user_id
22
+ attribute :joined, :from => :join_epoch
23
+ attribute :seller, :from => :is_seller
24
+ attribute :last_login, :from => :last_login_epoch
25
+
26
+ attributes :url, :city, :gender, :bio
27
+
28
+ # This user's shop, returns nil if user is not a seller. See Etsy::Shop
29
+ # for more information.
30
+ #
31
+ def shop
32
+ Shop.find_by_user_id(id) if seller?
33
+ end
34
+
35
+ # Is this user a seller?
36
+ #
37
+ def seller?
38
+ seller
39
+ end
40
+
41
+ # Time that this user joined the site
42
+ #
43
+ def joined_at
44
+ Time.at(joined)
45
+ end
46
+
47
+ # Time that this user last logged in
48
+ #
49
+ def last_login_at
50
+ Time.at(last_login)
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ module Etsy
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 0
7
+
8
+ def self.to_s # :nodoc:
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,70 @@
1
+ {
2
+ "count": 1,
3
+ "results": [{
4
+ "user_name": "littletjane",
5
+ "user_id": 5327518,
6
+ "url": "http:\/\/www.etsy.com\/shop.php?user_id=5327518",
7
+ "image_url_25x25": "http:\/\/ny-image3.etsy.com\/iusa_25x25.5874999.jpg",
8
+ "image_url_30x30": "http:\/\/ny-image3.etsy.com\/iusa_30x30.5874999.jpg",
9
+ "image_url_50x50": "http:\/\/ny-image3.etsy.com\/iusa_50x50.5874999.jpg",
10
+ "image_url_75x75": "http:\/\/ny-image3.etsy.com\/iusa_75x75.5874999.jpg",
11
+ "join_epoch": 1191381757.93,
12
+ "city": "Washington, DC",
13
+ "gender": "female",
14
+ "lat": null,
15
+ "lon": null,
16
+ "transaction_buy_count": 199,
17
+ "transaction_sold_count": 0,
18
+ "is_seller": true,
19
+ "was_featured_seller": false,
20
+ "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"],
21
+ "last_login_epoch": 1239797927.39,
22
+ "feedback_count": "171",
23
+ "feedback_percent_positive": "100",
24
+ "referred_user_count": 1,
25
+ "birth_day": "20",
26
+ "birth_month": "3",
27
+ "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...etsy!\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!",
28
+ "banner_image_url": "http:\/\/ny-image0.etsy.com\/iusb_760x100.6158980.jpg",
29
+ "last_updated_epoch": 1239717723.36,
30
+ "creation_epoch": 1237430331.15,
31
+ "listing_count": 13,
32
+ "shop_name": "littletjane",
33
+ "title": "title text",
34
+ "sale_message": "message text",
35
+ "announcement": "announcement text",
36
+ "is_vacation": "",
37
+ "vacation_message": "",
38
+ "currency_code": "USD",
39
+ "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:",
40
+ "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.",
41
+ "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.",
42
+ "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!",
43
+ "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!",
44
+ "sections": [{
45
+ "section_id": 6008529,
46
+ "title": "matchboxes",
47
+ "listing_count": 3
48
+ },
49
+ {
50
+ "section_id": 6008530,
51
+ "title": "original paintings",
52
+ "listing_count": 3
53
+ },
54
+ {
55
+ "section_id": 6059955,
56
+ "title": "sachets",
57
+ "listing_count": 5
58
+ },
59
+ {
60
+ "section_id": 6061498,
61
+ "title": "hand carved stamps",
62
+ "listing_count": 2
63
+ }]
64
+ }],
65
+ "params": {
66
+ "user_id": 5327518,
67
+ "detail_level": "high"
68
+ },
69
+ "type": "shop"
70
+ }
@@ -0,0 +1,135 @@
1
+ {
2
+ "count": 2,
3
+ "results": [{
4
+ "listing_id": 24165902,
5
+ "state": "active",
6
+ "title": "hanging with the bad boys matchbox",
7
+ "url": "http:\/\/www.etsy.com\/view_listing.php?listing_id=24165902",
8
+ "image_url_25x25": "http:\/\/ny-image2.etsy.com\/il_25x25.67765346.jpg",
9
+ "image_url_50x50": "http:\/\/ny-image2.etsy.com\/il_50x50.67765346.jpg",
10
+ "image_url_75x75": "http:\/\/ny-image2.etsy.com\/il_75x75.67765346.jpg",
11
+ "image_url_155x125": "http:\/\/ny-image2.etsy.com\/il_155x125.67765346.jpg",
12
+ "image_url_200x200": "http:\/\/ny-image2.etsy.com\/il_200x200.67765346.jpg",
13
+ "image_url_430xN": "http:\/\/ny-image2.etsy.com\/il_430xN.67765346.jpg",
14
+ "creation_epoch": 1240673494.49,
15
+ "views": 18,
16
+ "tags": ["accessories", "matchbox"],
17
+ "materials": ["standard_matchbox", "notebook_paper"],
18
+ "price": 3,
19
+ "currency_code": "USD",
20
+ "ending_epoch": 1251214294.49,
21
+ "hsv_color": "0;0;100",
22
+ "rgb_color": "#FFFFFF",
23
+ "user_id": 5327518,
24
+ "user_name": "littletjane",
25
+ "quantity": 1,
26
+ "description": "standard size matchbox ...",
27
+ "section_id": 6008529,
28
+ "section_title": "matchboxes",
29
+ "lat": null,
30
+ "lon": null,
31
+ "user_image_id": 5874999,
32
+ "city": "Washington, DC",
33
+ "all_images": [{
34
+ "image_url_25x25": "http:\/\/ny-image2.etsy.com\/il_25x25.67765346.jpg",
35
+ "image_url_50x50": "http:\/\/ny-image2.etsy.com\/il_50x50.67765346.jpg",
36
+ "image_url_75x75": "http:\/\/ny-image2.etsy.com\/il_75x75.67765346.jpg",
37
+ "image_url_155x125": "http:\/\/ny-image2.etsy.com\/il_155x125.67765346.jpg",
38
+ "image_url_200x200": "http:\/\/ny-image2.etsy.com\/il_200x200.67765346.jpg",
39
+ "image_url_430xN": "http:\/\/ny-image2.etsy.com\/il_430xN.67765346.jpg",
40
+ "hsv_color": "0;0;100",
41
+ "rgb_color": "#FFFFFF"
42
+ },
43
+ {
44
+ "image_url_25x25": "http:\/\/ny-image2.etsy.com\/il_25x25.67765298.jpg",
45
+ "image_url_50x50": "http:\/\/ny-image2.etsy.com\/il_50x50.67765298.jpg",
46
+ "image_url_75x75": "http:\/\/ny-image2.etsy.com\/il_75x75.67765298.jpg",
47
+ "image_url_155x125": "http:\/\/ny-image2.etsy.com\/il_155x125.67765298.jpg",
48
+ "image_url_200x200": "http:\/\/ny-image2.etsy.com\/il_200x200.67765298.jpg",
49
+ "image_url_430xN": "http:\/\/ny-image2.etsy.com\/il_430xN.67765298.jpg",
50
+ "hsv_color": "0;0;100",
51
+ "rgb_color": "#FFFFFF"
52
+ }]
53
+ },
54
+ {
55
+ "listing_id": 23555714,
56
+ "state": "active",
57
+ "title": "little t jane head hand carved stamp",
58
+ "url": "http:\/\/www.etsy.com\/view_listing.php?listing_id=23555714",
59
+ "image_url_25x25": "http:\/\/ny-image1.etsy.com\/il_25x25.65719221.jpg",
60
+ "image_url_50x50": "http:\/\/ny-image1.etsy.com\/il_50x50.65719221.jpg",
61
+ "image_url_75x75": "http:\/\/ny-image1.etsy.com\/il_75x75.65719221.jpg",
62
+ "image_url_155x125": "http:\/\/ny-image1.etsy.com\/il_155x125.65719221.jpg",
63
+ "image_url_200x200": "http:\/\/ny-image1.etsy.com\/il_200x200.65719221.jpg",
64
+ "image_url_430xN": "http:\/\/ny-image1.etsy.com\/il_430xN.65719221.jpg",
65
+ "creation_epoch": 1239482599.57,
66
+ "views": 42,
67
+ "tags": ["supplies", "handmade", "handcarved", "rubber_stamp", "embellishment", "scrapbooking", "ink", "paper_goods", "illustration", "happy", "smile", "littletjane", "cute", "funny"],
68
+ "materials": ["lino_cutters", "speedball_speedy_carve_block", "xacto_knife", "tracing_papers", "pencil", "ink", "wood", "foam_mounting_medium"],
69
+ "price": 7,
70
+ "currency_code": "USD",
71
+ "ending_epoch": 1250023399.57,
72
+ "hsv_color": "0;0;100",
73
+ "rgb_color": "#FFFFFF",
74
+ "user_id": 5327518,
75
+ "user_name": "littletjane",
76
+ "quantity": 1,
77
+ "description": "why, hello! a happy little head to stamp on all your papers.\r\n\r\nhand carved stamp lovingly carved on a highly durable, pink color eraser-like material that will not crack or crumble.\r\n\r\nfoam mounted on an approx. 1 x 1 inch wooden square. \r\n\r\n",
78
+ "section_id": 6061498,
79
+ "section_title": "hand carved stamps",
80
+ "lat": null,
81
+ "lon": null,
82
+ "user_image_id": 5874999,
83
+ "city": "Washington, DC",
84
+ "all_images": [{
85
+ "image_url_25x25": "http:\/\/ny-image1.etsy.com\/il_25x25.65719221.jpg",
86
+ "image_url_50x50": "http:\/\/ny-image1.etsy.com\/il_50x50.65719221.jpg",
87
+ "image_url_75x75": "http:\/\/ny-image1.etsy.com\/il_75x75.65719221.jpg",
88
+ "image_url_155x125": "http:\/\/ny-image1.etsy.com\/il_155x125.65719221.jpg",
89
+ "image_url_200x200": "http:\/\/ny-image1.etsy.com\/il_200x200.65719221.jpg",
90
+ "image_url_430xN": "http:\/\/ny-image1.etsy.com\/il_430xN.65719221.jpg",
91
+ "hsv_color": "0;0;100",
92
+ "rgb_color": "#FFFFFF"
93
+ },
94
+ {
95
+ "image_url_25x25": "http:\/\/ny-image1.etsy.com\/il_25x25.65719189.jpg",
96
+ "image_url_50x50": "http:\/\/ny-image1.etsy.com\/il_50x50.65719189.jpg",
97
+ "image_url_75x75": "http:\/\/ny-image1.etsy.com\/il_75x75.65719189.jpg",
98
+ "image_url_155x125": "http:\/\/ny-image1.etsy.com\/il_155x125.65719189.jpg",
99
+ "image_url_200x200": "http:\/\/ny-image1.etsy.com\/il_200x200.65719189.jpg",
100
+ "image_url_430xN": "http:\/\/ny-image1.etsy.com\/il_430xN.65719189.jpg",
101
+ "hsv_color": "0;0;100",
102
+ "rgb_color": "#FFFFFF"
103
+ },
104
+ {
105
+ "image_url_25x25": "http:\/\/ny-image1.etsy.com\/il_25x25.65719273.jpg",
106
+ "image_url_50x50": "http:\/\/ny-image1.etsy.com\/il_50x50.65719273.jpg",
107
+ "image_url_75x75": "http:\/\/ny-image1.etsy.com\/il_75x75.65719273.jpg",
108
+ "image_url_155x125": "http:\/\/ny-image1.etsy.com\/il_155x125.65719273.jpg",
109
+ "image_url_200x200": "http:\/\/ny-image1.etsy.com\/il_200x200.65719273.jpg",
110
+ "image_url_430xN": "http:\/\/ny-image1.etsy.com\/il_430xN.65719273.jpg",
111
+ "hsv_color": "0;0;100",
112
+ "rgb_color": "#FFFFFF"
113
+ },
114
+ {
115
+ "image_url_25x25": "http:\/\/ny-image0.etsy.com\/il_25x25.65719252.jpg",
116
+ "image_url_50x50": "http:\/\/ny-image0.etsy.com\/il_50x50.65719252.jpg",
117
+ "image_url_75x75": "http:\/\/ny-image0.etsy.com\/il_75x75.65719252.jpg",
118
+ "image_url_155x125": "http:\/\/ny-image0.etsy.com\/il_155x125.65719252.jpg",
119
+ "image_url_200x200": "http:\/\/ny-image0.etsy.com\/il_200x200.65719252.jpg",
120
+ "image_url_430xN": "http:\/\/ny-image0.etsy.com\/il_430xN.65719252.jpg",
121
+ "hsv_color": "0;0;100",
122
+ "rgb_color": "#FFFFFF"
123
+ }]
124
+ }],
125
+ "params": {
126
+ "user_id": 5327518,
127
+ "sort_on": "created",
128
+ "sort_order": "down",
129
+ "section_id": null,
130
+ "offset": 0,
131
+ "limit": 10,
132
+ "detail_level": "high"
133
+ },
134
+ "type": "listing"
135
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "count": 1,
3
+ "results": [{
4
+ "user_name": "littletjane",
5
+ "user_id": 5327518,
6
+ "url": "http:\/\/www.etsy.com\/shop.php?user_id=5327518",
7
+ "image_url_25x25": "http:\/\/ny-image3.etsy.com\/iusa_25x25.5874999.jpg",
8
+ "image_url_30x30": "http:\/\/ny-image3.etsy.com\/iusa_30x30.5874999.jpg",
9
+ "image_url_50x50": "http:\/\/ny-image3.etsy.com\/iusa_50x50.5874999.jpg",
10
+ "image_url_75x75": "http:\/\/ny-image3.etsy.com\/iusa_75x75.5874999.jpg",
11
+ "join_epoch": 1191381757.93,
12
+ "city": "Washington, DC",
13
+ "gender": "female",
14
+ "lat": null,
15
+ "lon": null,
16
+ "transaction_buy_count": 199,
17
+ "transaction_sold_count": 0,
18
+ "is_seller": true,
19
+ "was_featured_seller": false,
20
+ "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"],
21
+ "last_login_epoch": 1239797927.39,
22
+ "feedback_count": "171",
23
+ "feedback_percent_positive": "100",
24
+ "referred_user_count": 1,
25
+ "birth_day": "20",
26
+ "birth_month": "3",
27
+ "bio": "hello!"
28
+ }],
29
+ "params": {
30
+ "user_id": 5327518,
31
+ "detail_level": "high"
32
+ },
33
+ "type": "user"
34
+ }
@@ -0,0 +1,54 @@
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/etsy'
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 = Etsy::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
+ Etsy::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
+ class_eval do
37
+ define_method "setup_for_population" do
38
+ @object = klass.new(data)
39
+ end
40
+ end
41
+
42
+ block.call
43
+ end
44
+
45
+ def self.value_for(method_name, options)
46
+ class_eval do
47
+ it "should have a value for :#{method_name}" do
48
+ setup_for_population
49
+ @object.send(method_name).should == options[:is]
50
+ end
51
+ end
52
+ end
53
+
54
+ end