parsecom 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,6 +42,9 @@ Yet-Another Parse.com Library written in Pure Ruby
42
42
  - [Uploading Files](#uploading-files)
43
43
  - [Associating with Objects](#associating-with-objects)
44
44
  - [Deleting Files](#deleting-files)
45
+ - [Analytics](#analytics)
46
+ - [App-Open Analytics](#app-open-analytics)
47
+ - [Custom Analytics](#custom-analytics)
45
48
  - [Installations](#installations)
46
49
  - [Uploading Installation Data](#uploading-installation-data)
47
50
  - [Retrieving Installations](#retrieving-installations)
@@ -488,7 +491,30 @@ file.delete!
488
491
 
489
492
  ### Analytics
490
493
 
491
- TBD
494
+ #### App-Open Analytics
495
+
496
+ ```ruby
497
+ app_opened_event = Parse::Event::AppOpened.new :at => '2013-10-18T20:53:25Z'
498
+ app_opened_event.fire
499
+ ```
500
+
501
+ ```ruby
502
+ Parse::Event::AppOpened.fire :at => '2013-10-18T20:53:25Z'
503
+ ```
504
+
505
+ #### Custom Analytics
506
+
507
+ ```ruby
508
+ Parse::Event.create :Search
509
+ search_event = Search.new :at => '2013-10-18T20:53:25Z',
510
+ :priceRange => "1000-1500", :source => "craigslist", :dayType => "weekday"
511
+ search_event.fire
512
+ ```
513
+
514
+ ```ruby
515
+ error_event = Parse::Event::Error.new :at => '2013-10-18T20:53:25Z', :code => 404
516
+ error_event.fire
517
+ ```
492
518
 
493
519
  ### Push Notifications
494
520
 
@@ -558,7 +584,7 @@ place = PlaceObject.find :limit => 10, :where => proc {
558
584
  ```ruby
559
585
  places = PlaceObject.find :limit => 10, :where => proc {
560
586
  geo_point = Parse::GeoPoint.new :latitude => 30.0, :longitude => -20.0
561
- column(:location).near_sphere(geop_point).max_distance_in_miles(10.0)
587
+ column(:location).near_sphere(geo_point).max_distance_in_miles(10.0)
562
588
  }
563
589
  ```
564
590
 
data/lib/parse/client.rb CHANGED
@@ -41,7 +41,7 @@ module Parse
41
41
  endpoint = canonical_endpoint endpoint
42
42
  headers = build_headers opt_headers
43
43
  if body.is_a?(Hash)
44
- body = Hash[*(body.to_a.map{|k, v| [k, URI.encode(v)]}.flatten)].to_json
44
+ body = Hash[*(body.to_a.map{|k, v| [k, URI.encode(v.to_s)]}.flatten)].to_json
45
45
  end
46
46
  @http_client.request method, endpoint, headers, body, &block
47
47
  end
data/lib/parse/date.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Parse
2
+ class Date < Time
3
+ def to_h
4
+ {
5
+ "__type" => "Date",
6
+ "iso" => strftime('%Y-%m-%dT%H:%M:%SZ')
7
+ }
8
+ end
9
+
10
+ def to_json *args
11
+ to_h.to_json
12
+ end
13
+
14
+ def to_s
15
+ to_json
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,69 @@
1
+ # coding:utf-8
2
+ module Parse
3
+ RESERVED_EVENT_CLASS = {
4
+ 'AppOpened' => 'Parse::Event::AppOpened',
5
+ 'Error' => 'Parse::Event::Error'
6
+ }
7
+
8
+ class Event
9
+ include Parse::Util
10
+
11
+ @@event_class_vs_class_table = {}
12
+
13
+ class << self
14
+ attr_accessor :event_class_name, :parse_client
15
+
16
+ def register_event_class event_class
17
+ @@event_class_vs_class_table[event_class.event_class_name] = event_class
18
+ end
19
+
20
+ def create event_class_name, mod=::Object
21
+ raise 'already defined' if mod.const_defined? event_class_name
22
+
23
+ if RESERVED_EVENT_CLASS.has_key? event_class_name.to_s
24
+ eval RESERVED_EVENT_CLASS[event_class_name.to_s]
25
+ else
26
+ klass = Class.new(Parse::Event)
27
+ klass.event_class_name = event_class_name.to_sym
28
+ mod.const_set event_class_name, klass
29
+ register_event_class klass
30
+ end
31
+ end
32
+
33
+ def event_class_name
34
+ @event_class_name ||= name.split('::').last
35
+ end
36
+
37
+ def parse_client
38
+ @parse_client ||= Parse::Client.default
39
+ end
40
+
41
+ def fire hash={}
42
+ self.new(hash).fire
43
+ end
44
+ end
45
+
46
+ attr_accessor :at, :dimensions
47
+
48
+ def initialize hash={}
49
+ hash = string_keyed_hash hash
50
+ @at = hash.delete 'at'
51
+ @at = Parse::Date.parse @at if @at.is_a?(String)
52
+ @dimensions = hash.dup
53
+ end
54
+
55
+ def fire
56
+ body = @dimensions
57
+ body['at'] = @at if @at
58
+ parse_client.call_api :post, "events/#{event_class_name}", body.to_json
59
+ end
60
+
61
+ def parse_client
62
+ self.class.parse_client
63
+ end
64
+
65
+ def event_class_name
66
+ self.class.event_class_name
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ module Parse
2
+ class Event
3
+ class AppOpened < Event
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Parse
2
+ class Event
3
+ class Error < Event
4
+ end
5
+ end
6
+ end
data/lib/parse/object.rb CHANGED
@@ -92,7 +92,7 @@ module Parse
92
92
  when nil
93
93
  Parse::ACL.new v
94
94
  when 'Date'
95
- Date.parse v['iso']
95
+ Parse::Date.parse v['iso']
96
96
  when 'File'
97
97
  Parse::File.new v
98
98
  when 'Pointer'
@@ -157,7 +157,7 @@ module Parse
157
157
  method = use_master_key ? :create! : :create
158
158
  parse_client.send(method, self.parse_class_name, @updated_hash) do |response|
159
159
  @parse_object_id = response['objectId']
160
- @created_at = Date.parse response['createdAt']
160
+ @created_at = Parse::Date.parse response['createdAt']
161
161
  @updated_at = @created_at
162
162
  @raw_hash.update @updated_hash
163
163
  @raw_hash.update response
@@ -176,7 +176,7 @@ module Parse
176
176
  parse_client.send(method, parse_class_name, parse_object_id, hash) do |response|
177
177
  @raw_hash.update @updated_hash
178
178
  @raw_hash.update response
179
- @updated_at = Date.parse response['updatedAt']
179
+ @updated_at = Parse::Date.parse response['updatedAt']
180
180
  @updated_hash.clear
181
181
  end
182
182
  end
data/lib/parse/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Parse
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/parsecom.rb CHANGED
@@ -21,6 +21,7 @@ require 'parse/geo_point'
21
21
  require 'parse/pointer'
22
22
  require 'parse/relation'
23
23
  require 'parse/file'
24
+ require 'parse/date'
24
25
  require 'parse/op/increment'
25
26
  require 'parse/op/add'
26
27
  require 'parse/op/add_unique'
@@ -30,6 +31,9 @@ require 'parse/op/remove_relation'
30
31
  require 'parse/op/delete'
31
32
  require 'parse/batch'
32
33
  require 'parse/batch_http_client'
34
+ require 'parse/event'
35
+ require 'parse/event/app_opened'
36
+ require 'parse/event/error'
33
37
 
34
38
  module Parse
35
39
  @@application_id = ENV['PARSE_APPLICATION_ID']
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.4.0
4
+ version: 0.5.0
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-10-20 00:00:00.000000000 Z
12
+ date: 2013-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -77,6 +77,10 @@ files:
77
77
  - lib/parse/batch_http_client.rb
78
78
  - lib/parse/client.rb
79
79
  - lib/parse/cloud_code.rb
80
+ - lib/parse/date.rb
81
+ - lib/parse/event.rb
82
+ - lib/parse/event/app_opened.rb
83
+ - lib/parse/event/error.rb
80
84
  - lib/parse/ext/string.rb
81
85
  - lib/parse/file.rb
82
86
  - lib/parse/geo_point.rb