dcparker-shopify 0.1.9 → 0.2.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,41 @@
1
+ require "date"
2
+
3
+ class Time # :nodoc:all
4
+
5
+ ##
6
+ # Convert to ISO 8601 representation
7
+ #
8
+ # Time.now.to_json #=> "\"2008-03-28T17:54:20-05:00\""
9
+ #
10
+ # @return [String]
11
+ # ISO 8601 compatible representation of the Time object.
12
+ #
13
+ # @api public
14
+ def to_json(*)
15
+ self.xmlschema.to_json
16
+ end
17
+
18
+ ##
19
+ # Return receiver (for DateTime/Time conversion protocol).
20
+ #
21
+ # Time.now.to_time #=> Wed Nov 19 20:08:28 -0800 2008
22
+ #
23
+ # @return [Time] Receiver
24
+ #
25
+ # @api public
26
+ def to_time
27
+ self
28
+ end
29
+
30
+ ##
31
+ # Convert to DateTime (for DateTime/Time conversion protocol).
32
+ #
33
+ # Time.now.to_datetime #=> #<DateTime: 106046956823/43200,-1/3,2299161>
34
+ #
35
+ # @return [DateTime] DateTime object representing the same moment as receiver
36
+ #
37
+ # @api public
38
+ def to_datetime
39
+ DateTime.parse self.to_s
40
+ end
41
+ end
@@ -1,46 +1,23 @@
1
- require 'rubygems'
2
- require 'extlib'
3
- gem 'jnunemaker-httparty', '>=0.3.1'
4
- require 'httparty'
1
+ require 'shopify/extlib'
5
2
  require 'bigdecimal'
6
3
  require 'digest/md5'
7
4
 
8
- module Shopify
9
- def self.get(*args)
10
- puts "getting #{args.map {|i| i.inspect}.join(', ')}"
11
- super
12
- end
13
-
14
- def self.def_collections(*klasses)
15
- klasses.each do |klass|
16
- kn = klass.name.gsub(/.*::/,'')
17
- class_eval "
18
- def self.#{kn.snake_case.pluralize}(query_params={})
19
- json = get(\"#{klass.site_prefix}/#{kn.snake_case.pluralize}.xml\", :query => query_params)
20
- if json['#{kn.snake_case.pluralize}']
21
- json['#{kn.snake_case.pluralize}'].collect {|i| #{kn}.instantiate(i)}
22
- else
23
- json
24
- end
25
- end
26
- def self.#{kn.snake_case}(id)
27
- get(\"/#{kn.snake_case.pluralize}/\#{id}.xml\")
28
- end
29
- "
30
- end
31
- end
5
+ require 'rubygems'
6
+ gem 'jnunemaker-httparty', '=0.3.1'
7
+ require 'httparty'
32
8
 
9
+ class Shopify
33
10
  class ShopifyModel
34
11
  class << self
35
12
  def top_level(*options)
36
13
  klass_name = self.name.gsub(/.*::/,'')
37
14
  if options.include?(:singular)
38
15
  # Define singular accessor in Shopify
39
- eval "
40
- def Shopify.#{klass_name.snake_case}(query_params={})
41
- json = Shopify.get(\"/#{klass_name.snake_case}.xml\", :query => query_params)
16
+ Shopify.class_eval "
17
+ def #{klass_name.snake_case}(query_params={})
18
+ json = get(\"/#{klass_name.snake_case}.xml\", :query => query_params)
42
19
  begin
43
- #{klass_name}.instantiate json['#{klass_name.snake_case}']
20
+ #{klass_name}.instantiate(self, json['#{klass_name.snake_case}'])
44
21
  rescue => e
45
22
  warn \"Error: \#{e.inspect}\"
46
23
  json
@@ -49,19 +26,19 @@ module Shopify
49
26
  "
50
27
  else
51
28
  # Define plural accessor in Shopify
52
- eval "
53
- def Shopify.#{klass_name.snake_case.pluralize}(query_params={})
54
- json = Shopify.get(\"/#{klass_name.snake_case.pluralize}.xml\", :query => query_params)
29
+ Shopify.class_eval "
30
+ def #{klass_name.snake_case.pluralize}(query_params={})
31
+ json = get(\"/#{klass_name.snake_case.pluralize}.xml\", :query => query_params)
55
32
  if json['#{klass_name.snake_case.pluralize}']
56
- json['#{klass_name.snake_case.pluralize}'].collect {|i| #{klass_name}.instantiate(i)}
33
+ json['#{klass_name.snake_case.pluralize}'].collect {|i| #{klass_name}.instantiate(self, i)}
57
34
  else
58
35
  json
59
36
  end
60
37
  end
61
- def Shopify.#{klass_name.snake_case}(id)
62
- json = Shopify.get(\"/#{klass_name.snake_case.pluralize}/\#{id}.xml\")
38
+ def #{klass_name.snake_case}(id)
39
+ json = get(\"/#{klass_name.snake_case.pluralize}/\#{id}.xml\")
63
40
  if json['#{klass_name.snake_case}']
64
- #{klass_name}.instantiate json['#{klass_name.snake_case}']
41
+ #{klass_name}.instantiate(self, json['#{klass_name.snake_case}'])
65
42
  else
66
43
  json
67
44
  end
@@ -69,21 +46,21 @@ module Shopify
69
46
  "
70
47
  end
71
48
  end
72
- def child_of(parent_klass)
49
+ def children_of(parent_klass)
73
50
  @parent = parent_klass
74
51
  parent_klass_name = parent_klass.name.gsub(/.*::/,'')
75
52
  klass_name = self.name.gsub(/.*::/,'')
76
53
  parent_klass.class_eval "
77
54
  def #{klass_name.snake_case.pluralize}(query_params={})
78
55
  @#{klass_name.snake_case.pluralize} ||= begin
79
- json = Shopify.get(\"/#{parent_klass_name.snake_case.pluralize}/\#{id}/#{klass_name.snake_case.pluralize}.xml\", :query => query_params)
56
+ json = shop.get(\"/#{parent_klass_name.snake_case.pluralize}/\#{id}/#{klass_name.snake_case.pluralize}.xml\", :query => query_params)
80
57
  if json['#{parent_klass_name.snake_case}_#{klass_name.snake_case.pluralize}']
81
- json['#{parent_klass_name.snake_case}_#{klass_name.snake_case.pluralize}'].collect {|i| #{klass_name}.instantiate(i)}
58
+ json['#{parent_klass_name.snake_case}_#{klass_name.snake_case.pluralize}']
82
59
  else
83
60
  json
84
61
  end
85
62
  end
86
- @#{klass_name.snake_case.pluralize} = unless @#{klass_name.snake_case.pluralize}.is_a?(#{klass_name})
63
+ @#{klass_name.snake_case.pluralize} = (@#{klass_name.snake_case.pluralize}.is_a?(Array) ? @#{klass_name.snake_case.pluralize}.collect {|i| #{klass_name}.instantiate(shop, i)} : [#{klass_name}.instantiate(shop, @#{klass_name.snake_case.pluralize})]) unless @#{klass_name.snake_case.pluralize}.is_a?(#{klass_name}) || @#{klass_name.snake_case.pluralize}.is_a?(Array) && @#{klass_name.snake_case.pluralize}[0].is_a?(#{klass_name})
87
64
  @#{klass_name.snake_case.pluralize}
88
65
  end
89
66
  "
@@ -93,12 +70,18 @@ module Shopify
93
70
  end
94
71
  end
95
72
 
96
- def self.instantiate(attrs={})
97
- new(attrs.merge('new_record' => false))
73
+ def self.instantiate(shop, attrs={})
74
+ new(shop, attrs.merge('new_record' => false))
98
75
  end
99
- def initialize(attrs={})
76
+ def initialize(shop, attrs={})
100
77
  @new_record = true
101
78
  attrs.each { |k,v| instance_variable_set("@#{k}", v) }
79
+ @shop = shop
80
+ end
81
+ attr_accessor :shop
82
+
83
+ def inspect
84
+ "<#{self.class.name} shop=#{@shop.host} #{instance_variables.reject {|i| i=='@shop' || instance_variable_get(i).to_s==''}.map {|i| "#{i}=#{instance_variable_get(i).inspect}"}.join(' ')}>"
102
85
  end
103
86
  end
104
87
  end
data/shopify.gemspec CHANGED
@@ -2,18 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{shopify}
5
- s.version = "0.1.9"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Daniel Parker"]
9
- s.date = %q{2009-03-10}
9
+ # s.cert_chain = ["/Users/daniel/.gem_keys/gem-public_cert.pem"]
10
+ # s.signing_key = %q{/Users/daniel/.gem_keys/gem-private_key.pem}
11
+ s.date = %q{2009-04-16}
10
12
  s.description = %q{Easily communicate with Shopify.com's restful API.}
11
13
  s.email = %q{gems@behindlogic.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/shopify/support.rb", "lib/shopify.rb", "LICENSE", "README"]
13
- s.files = ["CHANGELOG", "lib/shopify/support.rb", "lib/shopify.rb", "LICENSE", "Manifest", "README", "shopify.gemspec"]
14
+ s.extra_rdoc_files = ["CHANGELOG", "lib/shopify/extlib/assertions.rb", "lib/shopify/extlib/class.rb", "lib/shopify/extlib/hash.rb", "lib/shopify/extlib/hook.rb", "lib/shopify/extlib/inflection.rb", "lib/shopify/extlib/logger.rb", "lib/shopify/extlib/object.rb", "lib/shopify/extlib/pathname.rb", "lib/shopify/extlib/rubygems.rb", "lib/shopify/extlib/string.rb", "lib/shopify/extlib/time.rb", "lib/shopify/extlib.rb", "lib/shopify/support.rb", "lib/shopify.rb", "LICENSE", "README.textile"]
15
+ s.files = ["CHANGELOG", "lib/shopify/extlib/assertions.rb", "lib/shopify/extlib/class.rb", "lib/shopify/extlib/hash.rb", "lib/shopify/extlib/hook.rb", "lib/shopify/extlib/inflection.rb", "lib/shopify/extlib/logger.rb", "lib/shopify/extlib/object.rb", "lib/shopify/extlib/pathname.rb", "lib/shopify/extlib/rubygems.rb", "lib/shopify/extlib/string.rb", "lib/shopify/extlib/time.rb", "lib/shopify/extlib.rb", "lib/shopify/support.rb", "lib/shopify.rb", "LICENSE", "Manifest", "README.textile", "shopify.gemspec"]
14
16
  s.has_rdoc = true
15
17
  s.homepage = %q{http://github.com/dcparker/shopify/tree}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Shopify", "--main", "README"]
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Shopify", "--main", "README.textile"]
17
19
  s.require_paths = ["lib"]
18
20
  s.rubyforge_project = %q{shopify}
19
21
  s.rubygems_version = %q{1.3.1}
@@ -24,11 +26,11 @@ Gem::Specification.new do |s|
24
26
  s.specification_version = 2
25
27
 
26
28
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<echoe>, [">= 0"])
29
+ s.add_runtime_dependency(%q<jnunemaker-httparty>, ["= 0", "= 0.3.1"])
28
30
  else
29
- s.add_dependency(%q<echoe>, [">= 0"])
31
+ s.add_dependency(%q<jnunemaker-httparty>, ["= 0", "= 0.3.1"])
30
32
  end
31
33
  else
32
- s.add_dependency(%q<echoe>, [">= 0"])
34
+ s.add_dependency(%q<jnunemaker-httparty>, ["= 0", "= 0.3.1"])
33
35
  end
34
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcparker-shopify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Parker
@@ -9,18 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-10 00:00:00 -07:00
12
+ date: 2009-04-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: echoe
17
- type: :development
16
+ name: jnunemaker-httparty
17
+ type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - "="
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
+ - - "="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.1
24
27
  version:
25
28
  description: Easily communicate with Shopify.com's restful API.
26
29
  email: gems@behindlogic.com
@@ -30,17 +33,41 @@ extensions: []
30
33
 
31
34
  extra_rdoc_files:
32
35
  - CHANGELOG
36
+ - lib/shopify/extlib/assertions.rb
37
+ - lib/shopify/extlib/class.rb
38
+ - lib/shopify/extlib/hash.rb
39
+ - lib/shopify/extlib/hook.rb
40
+ - lib/shopify/extlib/inflection.rb
41
+ - lib/shopify/extlib/logger.rb
42
+ - lib/shopify/extlib/object.rb
43
+ - lib/shopify/extlib/pathname.rb
44
+ - lib/shopify/extlib/rubygems.rb
45
+ - lib/shopify/extlib/string.rb
46
+ - lib/shopify/extlib/time.rb
47
+ - lib/shopify/extlib.rb
33
48
  - lib/shopify/support.rb
34
49
  - lib/shopify.rb
35
50
  - LICENSE
36
- - README
51
+ - README.textile
37
52
  files:
38
53
  - CHANGELOG
54
+ - lib/shopify/extlib/assertions.rb
55
+ - lib/shopify/extlib/class.rb
56
+ - lib/shopify/extlib/hash.rb
57
+ - lib/shopify/extlib/hook.rb
58
+ - lib/shopify/extlib/inflection.rb
59
+ - lib/shopify/extlib/logger.rb
60
+ - lib/shopify/extlib/object.rb
61
+ - lib/shopify/extlib/pathname.rb
62
+ - lib/shopify/extlib/rubygems.rb
63
+ - lib/shopify/extlib/string.rb
64
+ - lib/shopify/extlib/time.rb
65
+ - lib/shopify/extlib.rb
39
66
  - lib/shopify/support.rb
40
67
  - lib/shopify.rb
41
68
  - LICENSE
42
69
  - Manifest
43
- - README
70
+ - README.textile
44
71
  - shopify.gemspec
45
72
  has_rdoc: true
46
73
  homepage: http://github.com/dcparker/shopify/tree
@@ -51,7 +78,7 @@ rdoc_options:
51
78
  - --title
52
79
  - Shopify
53
80
  - --main
54
- - README
81
+ - README.textile
55
82
  require_paths:
56
83
  - lib
57
84
  required_ruby_version: !ruby/object:Gem::Requirement
data/README DELETED
@@ -1,9 +0,0 @@
1
- Example Usage:
2
-
3
- Shopify.current_session = Shopify::Session.new('store_name', 'api-key', 'api-secret')
4
- Shopify.current_session.token = 'api-session-token'
5
- Shopify.apply_current_session!
6
-
7
- Shopify::Shop.current
8
- Shopify::Product.find(:first)
9
- Shopify::Order.find(:first)