share_progress 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33f1a306cea9f7dddb34309332f1c21e8c74362b
4
- data.tar.gz: 0fd51832efb835b705b1ca5b20b84e834af6e84f
3
+ metadata.gz: 1085ad215b27e858778f873aec2b0bb199b42cad
4
+ data.tar.gz: 7b892b06976c903e60cad35a4b18c6ed2235acdf
5
5
  SHA512:
6
- metadata.gz: 913752b8ebbd327b7300621e16a87f73e3c3905b9e49df8205c76709aa86f46fefcaabdd36537fe233186ee9caba51436b843e322346adbd10fa17851b2b7e60
7
- data.tar.gz: 6973aca626b2927a057fa6e7b7d93b0240ea4b5cbfa81aac1cef6275bd916f7d6913d7aacf72427bdd265abab660f7a60212ace6eb733067a4416ac9815f4e2c
6
+ metadata.gz: 34910b6f8f38ad01cd3843cd95e24ff6d611983ab22d78db2ed894f5736c819206f4098e0bd2e706f920eaa8569a7ae89c7c0242fdf1c0b90037e9ca16e50131
7
+ data.tar.gz: 58dea5f71910110a3a4acc72abc8f21210d8c2374a5d18a2410b40193e9168e3b66089d2584329ad72b90a427d45f6edb6b2920f1897a4419c8105f848e15539
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # ShareProgress
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/share_progress`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ `ShareProgress` is a gem designed to make creating A/B tests of Share Buttons for advocacy webpages simple and direct. It wraps the ShareProgress HTTP API while providing a simple, ActiveRecord-like interface for creating, updating and deleting buttons on ShareProgress.org itself.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,15 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ The current version of `share_progress` is centered around `Button` and `Variant` classes. Currently, this gem wraps a subset of the [ShareProgress API](https://docs.google.com/document/d/1f1Jktt4gk9b3qugH8h-3bj6DoijQ3_6-RxUw5uq7DWU/edit#) intended to work within applications that need to create share buttons for use on their website.
24
+
25
+ Before beginning, the application will expect that your environment defines an Environment Variable named `SHARE_PROGRESS_API_KEY`. This key can be retrieved for your account from run.shareprogress.org.
26
+
27
+ `ShareProgress` defines an API for interacting with the button portion of the ShareProgress API that is similar to ActiveRecord. Creating a new button is as simple as calling `Button.new(params)` where the params in question are the variables of the button (see [Button parameter options](https://docs.google.com/document/d/1f1Jktt4gk9b3qugH8h-3bj6DoijQ3_6-RxUw5uq7DWU/edit#heading=h.66d9v1vnsmth) for more details). Button variants (which define A/B/X testing variants for testing share options on ShareProgress) can be added by setting the `variants` property of your created button, or added through the `add_or_update(variant)` method. Button variants can be defined as hashes containing the correct parameters (options for Variant values can be seen in the sample request in [the documentation](https://docs.google.com/document/d/1f1Jktt4gk9b3qugH8h-3bj6DoijQ3_6-RxUw5uq7DWU/edit#heading=h.mdykzbbhavff)) or by passing in instances of the `FacebookVariant`, `TwitterVariant` and `EmailVariant` classes.
28
+
29
+ To create or update your button and its variants, simply call `button.save`, which will marshal all your changes and submit them to the API. If the request is successful, `save` will return `true`, while errors will cause the method to return `false` and `button.errors` will contain the relevant errors on the save attempt.
30
+
31
+ **Note**: The API currently includes options for `destroy` on variants, which will, when complete, allow you to remove a variant from a button after that button has been saved. This is currently an experimental feature. It is not tested and unlikely to work reliably, if at all. These features should not be used in production.
26
32
 
27
33
  ## Development
28
34
 
@@ -32,7 +38,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
38
 
33
39
  ## Contributing
34
40
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/share_progress.
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SumOfUs/share_progress.
36
42
 
37
43
 
38
44
  ## License
@@ -20,12 +20,22 @@ module ShareProgress
20
20
  private
21
21
 
22
22
  def format_response(http_response)
23
+ check_api_error(http_response)
23
24
  formatted = http_response['response'].nil? ? [] : http_response['response']
24
25
  errors = http_response['success'] ? {} : http_response['message']
25
26
  formatted.each { |r| r['errors'] = errors }
26
27
  formatted
27
28
  end
28
29
 
30
+ def check_api_error(http_response)
31
+ return if http_response.code < 300
32
+ return if http_response.code == 404 || http_response.code == 422
33
+ error_msg = "Status #{http_response.code}: #{http_response['message']}\n" +
34
+ "Requesting: #{http_response.request.uri.to_s}\n" +
35
+ "With Body: #{http_response.request.raw_body}"
36
+ raise ApiError.new(error_msg)
37
+ end
38
+
29
39
  end
30
40
  end
31
41
  end
@@ -1,6 +1,7 @@
1
1
  module ShareProgress
2
2
  class ShareProgressError < StandardError; end
3
3
  class RecordNotFound < ShareProgressError; end
4
+ class ApiError < ShareProgressError; end
4
5
  class AnalyticsNotFound < ShareProgressError; end
5
6
  class CouldNotParseVariant < ShareProgressError; end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module ShareProgress
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -27,7 +27,8 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'rspec'
28
28
  spec.add_development_dependency 'webmock'
29
29
  spec.add_development_dependency 'vcr'
30
+ spec.add_development_dependency 'gem-release'
30
31
 
31
32
  # Runtime Dependencies
32
- spec.add_runtime_dependency 'httparty'
33
+ spec.add_runtime_dependency 'httparty', '>= 0.13'
33
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: share_progress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neal Donnelly
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-09-02 00:00:00.000000000 Z
12
+ date: 2015-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -82,19 +82,33 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: httparty
85
+ name: gem-release
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
- type: :runtime
91
+ type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: httparty
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0.13'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0.13'
98
112
  description:
99
113
  email:
100
114
  - NealJMD@gmail.com