cafepress_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ nbproject
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cafepress_api.gemspec
4
+ gemspec
5
+
6
+ gem 'rexml/document'
7
+ gem 'open-uri'
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cafepress_api/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cafepress_api"
7
+ s.version = CafePressAPI::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Benjamin Lee Smith"]
10
+ s.email = ["benjamin.lee.smith@gmail.com"]
11
+ s.homepage = "https://github.com/benjaminleesmith/cafepress_api"
12
+ s.summary = "A simple Ruby wrapper for the CafePress API."
13
+ s.description = %q{This is a simple Ruby wrapper for the CafePress API. It is a work in progress and does not cover everything in the API.}
14
+
15
+ s.rubyforge_project = "cafepress_api"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,3 @@
1
+ module CafePressAPI
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,50 @@
1
+ require 'rexml/document'
2
+ require 'open-uri'
3
+ module CafePressAPI
4
+ RESULTS_PER_PAGE = 100
5
+
6
+ def self.user_token(app_key = ENV['cp_app_key'], email = ENV['cp_email'], password = ENV['cp_password'])
7
+ content = ''
8
+ open("http://open-api.cafepress.com/authentication.getUserToken.cp?appKey=#{app_key}&email=#{email}&password=#{password}") do |s| content = s.read end
9
+ REXML::Document.new(content).root.text
10
+ end
11
+
12
+ def self.get_store_products(cafepress_store_id, app_key = ENV['cp_app_key'])
13
+ content = ''
14
+ products = []
15
+ open("http://open-api.cafepress.com/product.listByStore.cp?v=3&appKey=#{app_key}&storeId=#{cafepress_store_id}&page=0&pageSize=#{RESULTS_PER_PAGE}") do |s| content = s.read end
16
+ doc = REXML::Document.new(content)
17
+ doc.root.elements.to_a.each do |product|
18
+ begin
19
+ cafepress_back_design_id = product.get_elements("mediaConfiguration[@perspectives='Back']").first.attributes['designId']
20
+ rescue
21
+ cafepress_back_design_id = nil
22
+ end
23
+
24
+ products << {
25
+ :name => product.attributes['name'],
26
+ :default_caption => product.attributes['defaultCaption'],
27
+ :cafepress_product_id => product.attributes['id'],
28
+ :url => product.attributes['marketplaceUri'],
29
+ :cafepress_design_id => product.get_elements("mediaConfiguration[@perspectives='Front']").first.attributes['designId'],
30
+ :cafepress_back_design_id => cafepress_back_design_id
31
+ }
32
+ end
33
+ products
34
+ end
35
+
36
+ def self.get_design_url(cafepress_design_id, app_key = ENV['cp_app_key'])
37
+ content = ''
38
+ open("http://open-api.cafepress.com/design.find.cp?v=3&appKey=#{app_key}&id=#{cafepress_design_id}") do |s| content = s.read end
39
+ doc = REXML::Document.new(content)
40
+ doc.root.attributes['mediaUrl']
41
+ end
42
+
43
+ def self.get_store(cafepress_store_id, app_key = ENV['cp_app_key'])
44
+ content = ''
45
+ open("http://open-api.cafepress.com/store.findByStoreId.cp?v=3&appKey=#{app_key}&storeId=#{cafepress_store_id}") do |s| content = s.read end
46
+ doc = REXML::Document.new(content)
47
+
48
+ {:store_id => cafepress_store_id, :description => doc.root.attributes['description']}
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cafepress_api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Benjamin Lee Smith
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-26 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: This is a simple Ruby wrapper for the CafePress API. It is a work in progress and does not cover everything in the API.
23
+ email:
24
+ - benjamin.lee.smith@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - cafepress_api.gemspec
36
+ - lib/cafepress_api.rb
37
+ - lib/cafepress_api/version.rb
38
+ has_rdoc: true
39
+ homepage: https://github.com/benjaminleesmith/cafepress_api
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: cafepress_api
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: A simple Ruby wrapper for the CafePress API.
72
+ test_files: []
73
+