patreon 0.1.0 → 0.2.0

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: 099dc7242a83f365e34627068869909c160a4ad8
4
- data.tar.gz: 5a05a3f08d9dc9738771a470cab0fe25b2f7d2c9
3
+ metadata.gz: bee2755fa7bbe4c0dcb717fb13f8d5cf1b06cee5
4
+ data.tar.gz: d529a387ad7c3ed3db7827bdd22ac1a3a9bd8b15
5
5
  SHA512:
6
- metadata.gz: 548b98fb4223e057bdec954107651b1fddf21fe100e430617c7bf4aa1d964471b02c67a58b0a90ec5d5c0019f92a8f270e7cff9b08db2aa30175177a29cdfb62
7
- data.tar.gz: 0aa98b2f5aa6d7cb100cca8effb0aba6e5662b0e7de0145a2beb74518b0e972d50a0dd3846390a23973753189584d413af92d133dc96a22cd34c6cd5909f1687
6
+ metadata.gz: 0c6b2ea5492326a1488fe824053dd338b832abb052f0c1f61d3c57571a684c66348ce1d73c449bdd110bd00c40d5f98b4c5d19262c221efb05d165f65c5c3887
7
+ data.tar.gz: 777e1d8b36da247e966769486495f9d1b61590bc50a72450b91c879beb53652362c4c52ff6919b67c17bb0e90f48d0dbb986b36c3751d0f782c4e134e694272c
data/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ https://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2015-2016 Patreon, Inc.
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ https://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Patreon Integration for Ruby
2
+ Copyright 2015-2016 Patreon, Inc.
3
+
4
+ This product includes software developed at Patreon, Inc. (https://www.patreon.com/).
data/README.md CHANGED
@@ -5,7 +5,7 @@ Get the gem from [RubyGems](https://rubygems.org/gems/patreon)
5
5
 
6
6
  Step 1. Get your client_id and client_secret
7
7
  ---
8
- Visit the [OAuth Documentation Page](patreon.com/oauth2/documentation)
8
+ Visit the [OAuth Documentation Page](http://patreon.com/oauth2/documentation)
9
9
  while logged in as a Patreon creator to register your client.
10
10
 
11
11
  This will provide you with a `client_id` and a `client_secret`.
@@ -36,3 +36,25 @@ class OAuthController < ApplicationController
36
36
  end
37
37
  end
38
38
  ```
39
+
40
+ Step 3. (Optional) Customize your usage
41
+ ---
42
+ `Patreon::API` instances have four methods:
43
+ * `fetch_user(includes=nil, fields=nil)`
44
+ * `fetch_campaign(includes=nil, fields=nil)`
45
+ * `fetch_campaign_and_patrons(includes=nil, fields=nil)`
46
+ * `fetch_page_of_pledges(campaign_id, page_size, cursor=nil, includes=nil, fields=nil)`
47
+
48
+ The `includes` and `fields` arguments to these methods specify
49
+ the [related resources](http://jsonapi.org/format/#fetching-includes)
50
+ and the [resource attributes](http://jsonapi.org/format/#fetching-sparse-fieldsets)
51
+ you want returned by our API, as per the [JSON:API specification](http://jsonapi.org/).
52
+ The lists of valid `includes` and `fields` arguments are provided on `Patreon::Schemas`.
53
+ For instance, if you wanted to request the total amount a patron has ever paid to your campaign,
54
+ which is not included by default, you could do:
55
+ ```ruby
56
+ api_client = Patreon::API.new(patron_access_token)
57
+ patron_response = api_client.fetch_user(nil, {
58
+ 'pledge': Patreon::Schemas::Pledge.default_attributes + [Patreon::Schemas::Pledge::Attributes::TOTAL_HISTORICAL_AMOUNT_CENTS]
59
+ })
60
+ ```
@@ -1,4 +1,7 @@
1
1
  $: << File.dirname(__FILE__)
2
2
 
3
+ require 'patreon/utils/jsonapi/url_util'
4
+ require 'patreon/utils/enum'
5
+ require 'patreon/schemas'
3
6
  require 'patreon/oauth'
4
7
  require 'patreon/api'
@@ -8,27 +8,30 @@ module Patreon
8
8
  @access_token = access_token
9
9
  end
10
10
 
11
- def fetch_user
12
- get_json('current_user')
11
+ def fetch_user(includes=nil, fields=nil)
12
+ get_json(Utils::JSONAPI::URLUtil.build_url('current_user',includes,fields))
13
13
  end
14
14
 
15
- def fetch_campaign_and_patrons()
16
- get_json('current_user/campaigns?include=rewards,creator,goals,pledges')
15
+ def fetch_campaign(includes=nil, fields=nil)
16
+ get_json(Utils::JSONAPI::URLUtil.build_url('current_user/campaigns',includes,fields))
17
17
  end
18
18
 
19
- def fetch_campaign()
20
- get_json('current_user/campaigns?include=rewards,creator,goals')
19
+ def fetch_campaign_and_patrons(includes=nil, fields=nil)
20
+ includes ||= Schemas::Campaign.default_relationships + [Schemas::Campaign::Relationships::PLEDGES]
21
+ fetch_campaign(includes, fields)
21
22
  end
22
23
 
23
- def fetch_page_of_pledges(campaign_id, page_size, cursor=nil)
24
- url = "campaigns/#{campaign_id}/pledges?page%5Bcount%5D=#{CGI::escape(page_size.to_s)}"
24
+ def fetch_page_of_pledges(campaign_id, page_size, cursor=nil, includes=nil, fields=nil)
25
+ url = "campaigns/#{campaign_id}/pledges"
26
+ url += "?page%5Bcount%5D=#{CGI::escape(page_size.to_s)}"
25
27
  url += "&page%5Bcursor%5D=#{CGI::escape(cursor.to_s)}" if cursor
26
- get_json(url)
28
+ get_json(Patreon::Utils::JSONAPI::URLUtil.build_url(url,includes,fields))
27
29
  end
28
30
 
29
31
  private
30
32
 
31
33
  def get_json(suffix)
34
+ print "getting suffix #{suffix}"
32
35
  url = URI.parse("https://api.patreon.com/oauth2/api/#{suffix}")
33
36
  req = Net::HTTP::Get.new(url.to_s)
34
37
  req['Authorization'] = "Bearer #{@access_token}"
@@ -36,4 +39,4 @@ module Patreon
36
39
  JSON.parse(res.body)
37
40
  end
38
41
  end
39
- end
42
+ end
@@ -0,0 +1,7 @@
1
+ $: << File.dirname(__FILE__)
2
+
3
+ require 'schemas/campaign'
4
+ require 'schemas/goal'
5
+ require 'schemas/pledge'
6
+ require 'schemas/reward'
7
+ require 'schemas/user'
@@ -0,0 +1,83 @@
1
+ module Patreon
2
+ module Schemas
3
+ module Campaign
4
+ class Attributes
5
+ include Utils::Enum
6
+
7
+ define :SUMMARY, 'summary'
8
+ define :CREATION_NAME, 'creation_name'
9
+ define :PAY_PER_NAME, 'pay_per_name'
10
+ define :ONE_LINER, 'one_liner'
11
+ define :MAIN_VIDEO_EMBED, 'main_video_embed'
12
+ define :MAIN_VIDEO_URL, 'main_video_url'
13
+ define :IMAGE_SMALL_URL, 'image_small_url'
14
+ define :IMAGE_URL, 'image_url'
15
+ define :THANKS_VIDEO_URL, 'thanks_video_url'
16
+ define :THANKS_EMBED, 'thanks_embed'
17
+ define :THANKS_MSG, 'thanks_msg'
18
+ define :IS_MONTHLY, 'is_monthly'
19
+ define :IS_NSFW, 'is_nsfw'
20
+ define :IS_CHARGED_IMMEDIATELY, 'is_charged_immediately'
21
+ define :IS_CHARGE_UPFRONT_ELIGIBLE, 'is_charge_upfront_eligible'
22
+ define :IS_PLURAL, 'is_plural'
23
+ define :CREATED_AT, 'created_at'
24
+ define :PUBLISHED_AT, 'published_at'
25
+ define :PLEDGE_URL, 'pledge_url'
26
+ define :PLEDGE_SUM, 'pledge_sum'
27
+ define :PATRON_COUNT, 'patron_count'
28
+ define :CREATION_COUNT, 'creation_count'
29
+ define :OUTSTANDING_PAYMENT_AMOUNT_CENTS, 'outstanding_payment_amount_cents'
30
+ end
31
+
32
+ class Relationships
33
+ include Utils::Enum
34
+
35
+ define :REWARDS, 'rewards'
36
+ define :CREATOR, 'creator'
37
+ define :GOALS, 'goals'
38
+ define :PLEDGES, 'pledges'
39
+ define :CURRENT_USER_PLEDGE, 'current_user_pledge'
40
+ define :POST_AGGREGATION, 'post_aggregation'
41
+ define :CATEGORIES, 'categories'
42
+ define :PREVIEW_TOKEN, 'preview_token'
43
+ end
44
+
45
+ class << self
46
+ def default_attributes
47
+ [
48
+ Attributes::SUMMARY,
49
+ Attributes::CREATION_NAME,
50
+ Attributes::PAY_PER_NAME,
51
+ Attributes::ONE_LINER,
52
+ Attributes::MAIN_VIDEO_EMBED,
53
+ Attributes::MAIN_VIDEO_URL,
54
+ Attributes::IMAGE_SMALL_URL,
55
+ Attributes::IMAGE_URL,
56
+ Attributes::THANKS_VIDEO_URL,
57
+ Attributes::THANKS_EMBED,
58
+ Attributes::THANKS_MSG,
59
+ Attributes::IS_MONTHLY,
60
+ Attributes::IS_NSFW,
61
+ Attributes::IS_CHARGED_IMMEDIATELY,
62
+ Attributes::IS_PLURAL,
63
+ Attributes::CREATED_AT,
64
+ Attributes::PUBLISHED_AT,
65
+ Attributes::PLEDGE_URL,
66
+ Attributes::PLEDGE_SUM,
67
+ Attributes::PATRON_COUNT,
68
+ Attributes::CREATION_COUNT,
69
+ Attributes::OUTSTANDING_PAYMENT_AMOUNT_CENTS,
70
+ ]
71
+ end
72
+
73
+ def default_relationships
74
+ [
75
+ Relationships::REWARDS,
76
+ Relationships::CREATOR,
77
+ Relationships::GOALS,
78
+ ]
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,35 @@
1
+ module Patreon
2
+ module Schemas
3
+ module Goal
4
+ class Attributes
5
+ include Utils::Enum
6
+
7
+ define :AMOUNT_CENTS, 'amount_cents'
8
+ define :TITLE, 'title'
9
+ define :DESCRIPTION, 'description'
10
+ define :CREATED_AT, 'created_at'
11
+ define :REACHED_AT, 'reached_at'
12
+ end
13
+
14
+ class Relationships
15
+ end
16
+
17
+ class << self
18
+ def default_attributes
19
+ [
20
+ Attributes::AMOUNT_CENTS,
21
+ Attributes::TITLE,
22
+ Attributes::DESCRIPTION,
23
+ Attributes::CREATED_AT,
24
+ Attributes::REACHED_AT,
25
+ ]
26
+ end
27
+
28
+ def default_relationships
29
+ [
30
+ ]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ module Patreon
2
+ module Schemas
3
+ module Pledge
4
+ class Attributes
5
+ include Utils::Enum
6
+
7
+ define :AMOUNT_CENTS, 'amount_cents'
8
+ define :TOTAL_HISTORICAL_AMOUNT_CENTS, 'total_historical_amount_cents'
9
+ define :DECLINED_SINCE, 'declined_since'
10
+ define :CREATED_AT, 'created_at'
11
+ define :PLEDGE_CAP_CENTS, 'pledge_cap_cents'
12
+ define :PATRON_PAYS_FEES, 'patron_pays_fees'
13
+ define :UNREAD_COUNT, 'unread_count'
14
+ end
15
+
16
+ class Relationships
17
+ include Utils::Enum
18
+
19
+ define :PATRON, 'patron'
20
+ define :REWARD, 'reward'
21
+ define :CREATOR, 'creator'
22
+ define :ADDRESS, 'address'
23
+ define :CARD, 'card'
24
+ define :PLEDGE_VAT_LOCATION, 'pledge_vat_location'
25
+ end
26
+
27
+ class << self
28
+ def default_attributes
29
+ [
30
+ Attributes::AMOUNT_CENTS,
31
+ Attributes::DECLINED_SINCE,
32
+ Attributes::CREATED_AT,
33
+ Attributes::PLEDGE_CAP_CENTS,
34
+ Attributes::PATRON_PAYS_FEES,
35
+ ]
36
+ end
37
+
38
+ def default_relationships
39
+ [
40
+ Relationships::PATRON,
41
+ Relationships::REWARD,
42
+ Relationships::CREATOR,
43
+ Relationships::ADDRESS,
44
+ Relationships::PLEDGE_VAT_LOCATION,
45
+ ]
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ module Patreon
2
+ module Schemas
3
+ module Goal
4
+ class Attributes
5
+ include Utils::Enum
6
+
7
+ define :AMOUNT_CENTS, 'amount_cents'
8
+ define :USER_LIMIT, 'user_limit'
9
+ define :REMAINING, 'remaining'
10
+ define :DESCRIPTION, 'description'
11
+ define :REQUIRES_SHIPPING, 'requires_shipping'
12
+ define :CREATED_AT, 'created_at'
13
+ define :URL, 'url'
14
+ define :PATRON_COUNT, 'patron_count'
15
+ end
16
+
17
+ class Relationships
18
+ include Utils::Enum
19
+
20
+ define :CREATOR, 'creator'
21
+ end
22
+
23
+ class << self
24
+ def default_attributes
25
+ [
26
+ Attributes::AMOUNT_CENTS,
27
+ Attributes::USER_LIMIT,
28
+ Attributes::REMAINING,
29
+ Attributes::DESCRIPTION,
30
+ Attributes::REQUIRES_SHIPPING,
31
+ Attributes::CREATED_AT,
32
+ Attributes::URL,
33
+ Attributes::PATRON_COUNT,
34
+ ]
35
+ end
36
+
37
+ def default_relationships
38
+ [
39
+ Relationships::CREATOR
40
+ ]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,85 @@
1
+ module Patreon
2
+ module Schemas
3
+ module User
4
+ class Attributes
5
+ include Utils::Enum
6
+
7
+ define :EMAIL, 'email'
8
+ define :FIRST_NAME, 'first_name'
9
+ define :LAST_NAME, 'last_name'
10
+ define :FULL_NAME, 'full_name'
11
+ define :GENDER, 'gender'
12
+ define :STATUS, 'status'
13
+ define :VANITY, 'vanity'
14
+ define :ABOUT, 'about'
15
+ define :FACEBOOK_ID, 'facebook_id'
16
+ define :IMAGE_URL, 'image_url'
17
+ define :THUMB_URL, 'thumb_url'
18
+ define :THUMBNAILS, 'thumbnails'
19
+ define :YOUTUBE, 'youtube'
20
+ define :TWITTER, 'twitter'
21
+ define :FACEBOOK, 'facebook'
22
+ define :TWITCH, 'twitch'
23
+ define :IS_SUSPENDED, 'is_suspended'
24
+ define :IS_DELETED, 'is_deleted'
25
+ define :IS_NUKED, 'is_nuked'
26
+ define :CREATED, 'created'
27
+ define :URL, 'url'
28
+ define :LIKE_COUNT, 'like_count'
29
+ define :COMMENT_COUNT, 'comment_count'
30
+ define :IS_CREATOR, 'is_creator'
31
+ define :HIDE_PLEDGES, 'hide_pledges'
32
+ define :TWO_FACTOR_ENABLED, 'two_factor_enabled'
33
+ end
34
+
35
+ class Relationships
36
+ include Utils::Enum
37
+
38
+ define :PLEDGES, 'pledges'
39
+ define :CARDS, 'cards'
40
+ define :FOLLOWS, 'follows'
41
+ define :CAMPAIGN, 'campaign'
42
+ define :PRESENCE, 'presence'
43
+ define :SESSION, 'session'
44
+ define :LOCATIONS, 'locations'
45
+ define :CURRENT_USER_FOLLOW, 'current_user_follow'
46
+ define :PLEDGE_TO_CURRENT_USER, 'pledge_to_current_user'
47
+ end
48
+
49
+ class << self
50
+ def default_attributes
51
+ [
52
+ Attributes::EMAIL,
53
+ Attributes::FIRST_NAME,
54
+ Attributes::LAST_NAME,
55
+ Attributes::FULL_NAME,
56
+ Attributes::GENDER,
57
+ Attributes::STATUS,
58
+ Attributes::VANITY,
59
+ Attributes::ABOUT,
60
+ Attributes::FACEBOOK_ID,
61
+ Attributes::IMAGE_URL,
62
+ Attributes::THUMB_URL,
63
+ Attributes::THUMBNAILS,
64
+ Attributes::YOUTUBE,
65
+ Attributes::TWITTER,
66
+ Attributes::FACEBOOK,
67
+ Attributes::TWITCH,
68
+ Attributes::IS_SUSPENDED,
69
+ Attributes::IS_DELETED,
70
+ Attributes::IS_NUKED,
71
+ Attributes::CREATED,
72
+ Attributes::URL,
73
+ ]
74
+ end
75
+
76
+ def default_relationships
77
+ [
78
+ Relationships::CAMPAIGN,
79
+ Relationships::PLEDGES,
80
+ ]
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,53 @@
1
+ # from http://code.dblock.org/2011/03/16/how-to-define-enums-in-ruby.html
2
+
3
+ module Patreon
4
+ module Utils
5
+ module Enum
6
+ def initialize(key, value)
7
+ @key = key
8
+ @value = value
9
+ end
10
+
11
+ def key
12
+ @key
13
+ end
14
+
15
+ def value
16
+ @value
17
+ end
18
+
19
+ def self.included(base)
20
+ base.extend(ClassMethods)
21
+ end
22
+
23
+ module ClassMethods
24
+ def define(key, value)
25
+ @hash ||= {}
26
+ @hash[key] = self.new(key, value)
27
+ end
28
+
29
+ def const_missing(key)
30
+ @hash[key].value
31
+ end
32
+
33
+ def each
34
+ @hash.each do |key, value|
35
+ yield key, value
36
+ end
37
+ end
38
+
39
+ def all
40
+ @hash.values
41
+ end
42
+
43
+ def all_to_hash
44
+ hash = {}
45
+ each do |key, value|
46
+ hash[key] = value.value
47
+ end
48
+ hash
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ require 'uri'
2
+
3
+ module Patreon
4
+ module Utils
5
+ module JSONAPI
6
+ class URLUtil
7
+ def self.build_url(path, includes=nil, fields=nil)
8
+ connector = path.include?('?') ? '&' : '?'
9
+ params = {}
10
+ if includes
11
+ params.merge!({ 'include' => joined_or_null(includes) })
12
+ end
13
+ if fields
14
+ params.merge!(fields.reduce({}) {|memo, type_attributes|
15
+ type, attributes = type_attributes
16
+ memo.merge({ "fields[#{type}]" => joined_or_null(attributes) })
17
+ })
18
+ end
19
+ return "#{path}#{connector}#{URI.encode_www_form(params)}"
20
+ end
21
+
22
+ private
23
+
24
+ def self.joined_or_null(list)
25
+ list.length == 0 ? "null" : list.join(',')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "patreon"
7
- gem.version = "0.1.0"
8
- gem.authors = ["David Kettler"]
7
+ gem.version = "0.2.0"
8
+ gem.authors = ["Patreon"]
9
9
  gem.email = ["david@patreon.com"]
10
10
  gem.description = "Interact with the Patreon API via OAuth"
11
- gem.licenses = ["MIT"]
11
+ gem.licenses = ["Apache 2.0"]
12
12
  gem.summary = "Visit patreon.com/oauth2/documentation for more information."
13
13
  gem.homepage = "https://github.com/Patreon/patreon-ruby"
14
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patreon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - David Kettler
7
+ - Patreon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-15 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Interact with the Patreon API via OAuth
14
14
  email:
@@ -18,14 +18,24 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
+ - LICENSE
22
+ - NOTICE
21
23
  - README.md
22
24
  - lib/patreon.rb
23
25
  - lib/patreon/api.rb
24
26
  - lib/patreon/oauth.rb
27
+ - lib/patreon/schemas.rb
28
+ - lib/patreon/schemas/campaign.rb
29
+ - lib/patreon/schemas/goal.rb
30
+ - lib/patreon/schemas/pledge.rb
31
+ - lib/patreon/schemas/reward.rb
32
+ - lib/patreon/schemas/user.rb
33
+ - lib/patreon/utils/enum.rb
34
+ - lib/patreon/utils/jsonapi/url_util.rb
25
35
  - patreon.gemspec
26
36
  homepage: https://github.com/Patreon/patreon-ruby
27
37
  licenses:
28
- - MIT
38
+ - Apache 2.0
29
39
  metadata: {}
30
40
  post_install_message:
31
41
  rdoc_options: []