parsecom 0.5.9 → 0.5.10

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.
@@ -4,21 +4,33 @@ module Parse
4
4
  include Util
5
5
 
6
6
  class <<self
7
- def parse str
8
- new :iso => str
7
+ def parse *args
8
+ if args.size == 1 && args.first.is_a?(String)
9
+ new :iso => args.first
10
+ else
11
+ new.tap do |dt|
12
+ dt.time = Time.gm *args
13
+ end
14
+ end
9
15
  end
10
16
  end
11
17
 
18
+ attr_accessor :time
19
+
12
20
  def initialize hash={}
13
21
  hash = string_keyed_hash hash
14
22
  @raw_hash = hash
15
23
  @time = ::Time.parse hash['iso'] if hash.has_key? 'iso'
16
24
  end
17
25
 
26
+ def <=> other
27
+ self.time <=> other.time
28
+ end
29
+
18
30
  def to_h
19
31
  {
20
32
  "__type" => "Date",
21
- "iso" => @time.strftime('%Y-%m-%dT%H:%M:%SZ')
33
+ "iso" => @time.iso8601
22
34
  }
23
35
  end
24
36
 
@@ -34,4 +46,10 @@ module Parse
34
46
  @time.__send__ name, *args, &block
35
47
  end
36
48
  end
49
+
50
+ module_function
51
+
52
+ def date *args
53
+ ParseDate.parse *args
54
+ end
37
55
  end
@@ -52,7 +52,9 @@ module Parse
52
52
  raw_results = parse_client.find(self.parse_class_name, object_id_or_conditions, opts)
53
53
  results = [raw_results].flatten
54
54
  results.map! {|hash| self.new hash} # TODO: should be recursive
55
- results.query_count = raw_results.query_count
55
+ if raw_results.is_a? Array
56
+ results.query_count = raw_results.query_count
57
+ end
56
58
  results
57
59
  end
58
60
 
@@ -65,7 +67,9 @@ module Parse
65
67
  raw_results = parse_client.find!(self.parse_class_name, object_id_or_conditions, opts)
66
68
  results = [raw_results].flatten
67
69
  results.map! {|hash| self.new hash}
68
- results.query_count = raw_results.query_count
70
+ if raw_results.is_a? Array
71
+ results.query_count = raw_results.query_count
72
+ end
69
73
  results
70
74
  end
71
75
 
@@ -203,6 +203,14 @@ module Parse
203
203
  alias greater_that_or_equal_to gte
204
204
  alias not_equal_to ne
205
205
 
206
+ def between range
207
+ if range.exclude_end?
208
+ self.gt(range.begin).lt(range.end)
209
+ else
210
+ self.gte(range.begin).lte(range.end)
211
+ end
212
+ end
213
+
206
214
  def exists val=true
207
215
  @conditions.push ['$exists', val]
208
216
  self
@@ -212,6 +220,9 @@ module Parse
212
220
  %w(in nin all).each do |op|
213
221
  eval %Q{
214
222
  def #{op} *vals
223
+ if vals.size == 1 && vals.first.is_a?(Array)
224
+ vals = vals.first
225
+ end
215
226
  @conditions.push ['$#{op}', vals]
216
227
  self
217
228
  end
@@ -1,3 +1,3 @@
1
1
  module Parse
2
- VERSION = "0.5.9"
2
+ VERSION = "0.5.10"
3
3
  end
@@ -6,6 +6,7 @@ require 'open-uri'
6
6
  require 'fileutils'
7
7
  require 'json'
8
8
  require 'date'
9
+ require 'time'
9
10
  require 'net/https'
10
11
  require 'uri'
11
12
  require 'parse/ext/array'
@@ -10,6 +10,13 @@ describe Parse::ParseDate, 'when converting from and to json' do
10
10
  date.to_json.should == '{"__type":"Date","iso":"2013-10-18T20:53:25Z"}'
11
11
  end
12
12
 
13
+ it 'should be converted to a correct json' do
14
+ date = Parse::ParseDate.parse 2013, 10, 18, 20, 53, 25
15
+ date.year.should == 2013
16
+ date.month.should == 10
17
+ date.to_json.should == '{"__type":"Date","iso":"2013-10-18T20:53:25Z"}'
18
+ end
19
+
13
20
  it 'should be converted from a json' do
14
21
  date = Parse::ParseDate.new :iso => '2013-10-18T20:53:25Z'
15
22
  date.year.should == 2013
@@ -30,4 +30,8 @@ VCR.configure do |c|
30
30
  filter_sensitive_header(c, 'X-Parse-Session-Token')
31
31
  end
32
32
 
33
+ ENV['PARSE_APPLICATION_ID'] ||= 'dummy_app_id'
34
+ ENV['PARSE_API_KEY'] ||= 'dummy_api_key'
35
+ ENV['PARSE_MASTER_KEY'] ||= 'dummy_master_key'
36
+
33
37
  require 'parsecom'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsecom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-05 00:00:00.000000000 Z
12
+ date: 2013-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec