require File.dirname(__FILE__) + '/../lib/etsy4r' require 'yaml' # Read the Etsy API Documentation # http://developer.etsy.com/docs # Initialize a new Etsy API Client client = Etsy4r::Client.new('your_api_key') # Initialize a ServerCommands object server = Etsy4r::ServerCommands.new(client) # Ping the server res = server.ping # Return a list of all available method calls res = server.get_method_table # Get the current time on the Etsy server in epoch res = server.get_server_epoch # Go from epoch time to ruby Time object puts Time.at(res.results.first) # Every call return a response object # Below are the following methods on that object # These methods are available on every single call except on the image parser object if res.success? puts res.body .to_yaml # Return the full body response of the call puts res.results.to_yaml # Return the results (the actual deta) in an array of hashes puts res.count # Count of all pieces of data that the Query returned (note: this is a total count not the count returned) puts res.limit # The max number of records returned in the API call puts res.type # The type of result passed back puts res.params # The params passed in to the query else puts res.error_message # If the call was not successful an error message is returned end # Initialize a GiftGuideCommands object gift_guide = Etsy4r::GiftGuideCommands.new(client) # Get a list of available GiftGuides res = gift_guide.get_gift_guides # Get the listings for a gift guide # The first params is the id of the gift guide # This method takes the following optional params # :offset default = 0 type = int # :limit default = 10 type = int, max = 50 # :detail_level default = 'low' options = enum(low, medium, high) res = gift_guide.get_gift_guide_listings(61, {:detail_level => "high"}) # Initialize a UserCommands object user = Etsy4r::UserCommands.new(client) # Return the details for a user # You can pass a user id: res = user.get_user_details(5565464) # Or a user_name res = user.get_user_details('maymaydesigns') # Also, this methods take the :detail_level optional param res = user.get_user_details('maymaydesigns', {:detail_level => 'high'}) # Search for users by name # The search name is required # The method takes the :detail_level, :limit and :offset optional params res = user.get_users_by_name('amanda', {:detail_level => 'medium', :limit => 50}) # Initialize a ShopCommands object shop = Etsy4r::ShopCommands.new(client) # Get shop details, this method takes either a user_id or user_name # Also takes the :detail_level optional params res = shop.get_shop_details(5565464) res = shop.get_shop_details('maymaydesigns') # Returns a list of featured selers, not params res = shop.get_featured_sellers # Returns all listings for a "shop" (or user) # Takes either a user_id or a user_name # Also takes :detail_level, :limit and :offset optional params res = shop.get_listings(5565464) res = shop.get_listings('maymaydesigns') # Search for shops be a name # The name params is required # Take the following optional params # :detail_level, :limit, :offset # :sort_order default => 'down' enum (down, up) res = shop.get_shops_by_name('amanda') # Get a shops feauted listings # Takes either a user_id or user_name # Also taks the :detail_level optional_param res = shop.get_featured_details(5565464) res = shop.get_featured_details('maymaydesigns', :detail_level => 'high') # Initialize a TagCommands object tag = Etsy4r::TagCommands.new(client) # Returns the top level tags, no params res = tag.get_top_tags # Returns the child tags of a tag # Spaces and dashes get converted to underscores res = tag.get_child_tags('bags-and-purses') res = tag.get_child_tags('bags and purses') res = tag.get_child_tags('bags_and_purses') # Initialiaze a ListingCommands object listing = Etsy4r::ListingCommands.new(client) # Returns details for a specific listing # Takes the listing_id as a params and the optional :detail_level param res = listing.get_listing_details(19781773, :detail_level => 'high') # Returns listings that match the tags # Pass tags in as an array # Takes the following optional params # :sort_on default => 'created' enum(created, price) # :sort_order detfault => 'down' enum(up, down) # :detail_level, :limit, :offset res = listing.get_listings_by_tags(['bags_and_purses', 'art', 'shoulder bag']) res = listing.get_listings_by_tags(['bags_and_purses', 'art', 'shoulder bag'], :sort_on => 'price', :sort_order => 'down') # Return listings that match keywords # Takes an array of keywords # Takes the following optional params # :min_price default => NULL type = float # :max_price default => NULL type = float # :search_description default => false enum(true, false) # :sort_order, :sort_on, :detail_level, :limit, :offset res = listing.get_listings_by_keywords(['bags and purses', 'art', 'shoulder bag']) res = listing.get_listings_by_keywords(['bags and purses', 'art', 'shoulder bag'], :min_price => 0, :max_price => 22.99) # Returns the list of listings featured on the etsy homepage # No required params # Optional params # :detail_level, :limit, :offset res = listing.get_front_featured_listings res = listing.get_front_featured_listings(:detail_level => 'medium', :limit => '45') # Initialize a FavoriteCommands object favorite = Etsy4r::FavoriteCommands.new(client) # Returns the users who favorited the user passed in # Takes either a user_id or user_name # Optional params # :detail_level, :limit, :offset res = favorite.get_favorers_of_user(5565464) res = favorite.get_favorers_of_user(5565464, :detail_level => 'high', :limit => 5, :offset => 5) # Returns the users who favorited the listing passed in # Takes a listing_id # Optional params # :detail_level, :limit, :offset res = favorite.get_favorers_of_listing(19749826) res = favorite.get_favorers_of_listing(19749826, :detail_level => 'high', :limit => 5, :offset => 5) # Returns the users who the user passed in favorited # Takes either a user_id or user_name # Optional params # :detail_level, :limit, :offset res = favorite.get_favorite_shops_of_user(5565464) res = favorite.get_favorite_shops_of_user(5565464, :detail_level => 'high', :limit => 5, :offset => 5) # Returns the listings who the user passed in favorited # Takes either a user_id or user_name # Optional params # :detail_level, :limit, :offset res = favorite.get_favorite_listings_of_user(5565464) res = favorite.get_favorite_listings_of_user(5565464, :detail_level => 'high', :limit => 5, :offset => 5) # Initialize an ImageParser object # This takes a single parameter which is the id of an Etsy listing image_parser = Etsy4r::ImageParser.new(19781773) # Calling images on the object return a hash of the images # The hash contains all the formatted URLs that Etsy returns # (for the single image they give for a listing) puts image_parser.images.to_yaml