populr 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,120 @@
1
1
  = Populr.me Ruby Gem
2
2
 
3
- A rubygem for interacting with the Populr.me API from Ruby apps.
3
+ A rubygem for interacting with the Populr.me API from Ruby apps. If you're just getting started, be sure to check out the sample app at http://github.com/populr/populr_api_ruby_sample
4
+
5
+ === Getting an API Key
6
+
7
+ Read the 'Getting Started' section of the API documentation, which explains how to get an API key and create API templates on the Populr.me website:
8
+ http://developers.populr.me/api
9
+
10
+
11
+ === Retrieving and Listing Pops and Templates
12
+
13
+ # Create an API Connection
14
+ require 'populr'
15
+ @populr = Populr.new(<Your API Key>)
16
+
17
+ # List the templates in your populr account
18
+ @populr.templates.each do |template|
19
+ puts template.id
20
+ end
21
+
22
+ # Fetch a specific template
23
+ @template = @populr.templates.first
24
+ @template = @populr.templates.find(params[:template_id])
25
+
26
+ # List the pops that have already been created with a template
27
+ @template.pops.each do |pop|
28
+ puts pop.id
29
+ end
30
+
31
+ # List pops 100-150
32
+ @template.pops.range(100,50).each do |pop|
33
+ puts pop.id
34
+ end
35
+
36
+
37
+ === Creating & Publishing a Pop
38
+
39
+ # You must always create a pop from an existing template created
40
+ # on Populr.me
41
+ template = @populr.templates.find(<Template ID>)
42
+ pop = Pop.new(template)
43
+
44
+ # Assign it's title, slug, and other properties
45
+ p.slug = params[:pop_data]['slug']
46
+
47
+ # Fill in {{tags}} in the body of the pop using the
48
+ # values the user has provided in the pop_data parameter
49
+ for tag,value in params[:pop_data]['tags']
50
+ p.populate_tag(tag, value)
51
+ end
52
+
53
+ # Optionally set a password that will be required to view
54
+ p.password = 'pass'
55
+
56
+ # Save the pop. This commits our changes above.
57
+ p.save!
58
+
59
+ # Publish the pop. This makes it available at http://p.domain/p.slug.
60
+ # The pop model is updated with a valid published_pop_url after this line!
61
+ p.publish!
62
+
63
+
64
+ === Creating Assets
65
+
66
+ # Create a new image asset and fill the region named
67
+ # 'profile-image-region' with it.
68
+ file = File.open('my-image.jpg', 'r')
69
+ asset = @populr.images.build(file, 'Image Name').save!
70
+ p.populate_region('profile-image-region', asset)
71
+
72
+ # Fill in an embed regions by creating a new embed asset with HTML
73
+ html = "My HTML"
74
+ asset = @populr.embeds.build(html).save!
75
+ p.populate_region('youtube-region', asset)
76
+
77
+
78
+ === Creating Tracers
79
+
80
+ # Create a new tracer for our pop. This will allow us to collect
81
+ # analytics when users visit the page with the tracer code added.
82
+ tracer = pop.tracers.build
83
+ tracer.name = 'bengotow@gmail.com'
84
+ tracer.enable_webhook('http://mysite.com/tracer_viewed/%{pop-id}')
85
+ tracer.save!
86
+
87
+ # The URL (with the ?tc tracer extension) to give to the user.
88
+ traced_url = #{pop.published_pop_url}?#{tracer.code}
89
+
90
+
91
+ === Retrieving Tracer Analytics
92
+
93
+ pop = @populr.pops.find('<Pop ID>')
94
+ tracer = pop.tracers.find('<Tracer ID>')
95
+
96
+ # Fetch the number of views
97
+ puts tracer.views
98
+
99
+ # Fetch the number of clicks for a particular asset we placed in a region
100
+ puts tracer.clicks_for_asset('<Asset ID>')
101
+
102
+ # Fetch the number of clicks within an entire region (for example, clicks on
103
+ # a set of documents that were all placed in the same region.)
104
+ puts tracer.clicks_for_region('profile-image-region')
105
+
106
+
107
+ == Best Practices & Tips
108
+
109
+ * Create template pops using the Populr.me website that have everything _except_ what you need to insert via the API.
110
+ * Show a list of available templates to users, or store template IDs on your server or hardcode them into your app.
111
+ You cannot perform 'where' queries using the Populr API, so you can't retrieve pops or template by name or labels.
112
+ * Avoid creating the same asset each time you create a pop. If you plan to put the same image, document or embed in
113
+ multiple pops, create the assets ahead of time and insert them into each pop.
114
+ * Consider using the tracer name property to store extra information, such as a user ID or email address.
115
+ * Do not create hundreds of pops in a hard loop. If you make an exessive number of requests in a small period of time,
116
+ your API access may be suspended. Use Resque or a rake task to push pop creation to the background.
117
+
4
118
 
5
119
  == Contributing to the Populr.me Ruby Gem
6
120
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data/lib/pop.rb CHANGED
@@ -15,6 +15,14 @@ class Pop < RestfulModel
15
15
  attr_accessor :published_pop_url
16
16
  attr_accessor :unpopulated_api_regions
17
17
  attr_accessor :unpopulated_api_tags
18
+ attr_accessor :custom_links
19
+ attr_accessor :custom_code
20
+ attr_accessor :clone_link_enabled
21
+ attr_accessor :clone_link_url
22
+ attr_accessor :collaboration_link_enabled
23
+ attr_accessor :collaboration_interstitial_text
24
+ attr_accessor :collaboration_link_url
25
+ attr_accessor :collaboration_webhook
18
26
  attr_accessor :domain
19
27
  attr_accessor :password
20
28
 
@@ -27,8 +35,10 @@ class Pop < RestfulModel
27
35
  self.template_id = parent._id
28
36
  self.title = parent.title
29
37
  self.name = parent.name
30
- self.unpopulated_api_regions = parent.api_regions
31
- self.unpopulated_api_tags = parent.api_tags
38
+ self.unpopulated_api_regions = parent.api_regions.dup
39
+ self.unpopulated_api_tags = parent.api_tags.dup
40
+ self.custom_code = parent.custom_code
41
+ self.custom_links = parent.custom_links.dup
32
42
 
33
43
  elsif parent.is_a?(RestfulModelCollection)
34
44
  @_api = parent.instance_variable_get :@_api
@@ -78,6 +88,28 @@ class Pop < RestfulModel
78
88
  update('POST', 'unpublish')
79
89
  end
80
90
 
91
+ def enable_collaboration!(interstitial_text = '', webhook = nil)
92
+ self.collaboration_link_enabled = true
93
+ self.collaboration_webhook = webhook
94
+ self.collaboration_interstitial_text = interstitial_text
95
+ self.save! # go and populate our model with the collaboration link
96
+ end
97
+
98
+ def disable_collaboration
99
+ self.collaboration_link_enabled = false
100
+ self.collaboration_link_url = nil
101
+ end
102
+
103
+ def enable_cloning!
104
+ self.clone_link_enabled = true
105
+ self.save! # go and populate our model with the clone link
106
+ end
107
+
108
+ def disable_cloning
109
+ self.clone_link_enabled = false
110
+ self.clone_link_url = nil # doesn't get saed, just for developer interface
111
+ end
112
+
81
113
  def has_unpopulated_region(region_identifier)
82
114
  self.unpopulated_api_regions.include?(region_identifier)
83
115
  end
data/lib/restful_model.rb CHANGED
@@ -43,10 +43,14 @@ class RestfulModel
43
43
  setters = methods.grep(/^\w+=$/)
44
44
  setters.each do |setter|
45
45
  getter = setter.to_s[0..setter.to_s.index('=')-1]
46
- hash[getter] = self.send(getter)
47
-
48
- if hash[getter].class.method_defined? :as_json
49
- hash[getter] = hash[getter].as_json(options)
46
+ unless options[:except] && options[:except].include?(getter)
47
+ value = self.send(getter)
48
+ unless value.is_a? RestfulModelCollection
49
+ hash[getter] = value
50
+ if value.class.method_defined? :as_json
51
+ value = value.as_json(options)
52
+ end
53
+ end
50
54
  end
51
55
  end
52
56
  hash
data/lib/template.rb CHANGED
@@ -7,6 +7,8 @@ class Template < RestfulModel
7
7
  attr_accessor :label_names
8
8
  attr_accessor :api_tags
9
9
  attr_accessor :api_regions
10
+ attr_accessor :custom_code
11
+ attr_accessor :custom_links
10
12
 
11
13
  def pops
12
14
  @pops ||= RestfulModelCollection.new(Pop, @_api, self)
data/populr.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "populr"
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Gotow"]
12
- s.date = "2013-04-24"
12
+ s.date = "2013-05-22"
13
13
  s.description = "Gem for interacting with the Populr.me API that allows you to create and publish one-page websites, subscribe to web hooks and receive events when those pages are interacted with. Visit http://www.populr.me/ for more information. "
14
14
  s.email = "ben@populr.me"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: populr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-24 00:00:00.000000000 Z
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &70343202086340 !ruby/object:Gem::Requirement
16
+ requirement: &70304957231240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70343202086340
24
+ version_requirements: *70304957231240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &70343202085160 !ruby/object:Gem::Requirement
27
+ requirement: &70304957230380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70343202085160
35
+ version_requirements: *70304957230380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &70343202084200 !ruby/object:Gem::Requirement
38
+ requirement: &70304957229640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70343202084200
46
+ version_requirements: *70304957229640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70343202082840 !ruby/object:Gem::Requirement
49
+ requirement: &70304957227780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.3.5
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70343202082840
57
+ version_requirements: *70304957227780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70343202081860 !ruby/object:Gem::Requirement
60
+ requirement: &70304957226680 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 1.8.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70343202081860
68
+ version_requirements: *70304957226680
69
69
  description: ! 'Gem for interacting with the Populr.me API that allows you to create
70
70
  and publish one-page websites, subscribe to web hooks and receive events when those
71
71
  pages are interacted with. Visit http://www.populr.me/ for more information. '
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: -4567027092822148073
119
+ hash: -668596441403544786
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements: