thecity 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.md +45 -0
- data/README.md +170 -0
- data/Rakefile +11 -0
- data/lib/the_city/account.rb +32 -0
- data/lib/the_city/api/accounts.rb +34 -0
- data/lib/the_city/api/client.rb +136 -0
- data/lib/the_city/api/events.rb +55 -0
- data/lib/the_city/api/groups.rb +41 -0
- data/lib/the_city/api/needs.rb +51 -0
- data/lib/the_city/api/oauth.rb +50 -0
- data/lib/the_city/api/prayers.rb +51 -0
- data/lib/the_city/api/request/multipart_with_file.rb +36 -0
- data/lib/the_city/api/response/parse_json.rb +27 -0
- data/lib/the_city/api/response/raise_error.rb +28 -0
- data/lib/the_city/api/topics.rb +51 -0
- data/lib/the_city/api/users.rb +78 -0
- data/lib/the_city/api/utils.rb +58 -0
- data/lib/the_city/arguments.rb +11 -0
- data/lib/the_city/base.rb +133 -0
- data/lib/the_city/client.rb +94 -0
- data/lib/the_city/collection.rb +130 -0
- data/lib/the_city/content.rb +29 -0
- data/lib/the_city/error/argument_arror.rb +8 -0
- data/lib/the_city/error/bad_gateway.rb +10 -0
- data/lib/the_city/error/bad_request.rb +10 -0
- data/lib/the_city/error/configuration_error.rb +8 -0
- data/lib/the_city/error/forbidden.rb +10 -0
- data/lib/the_city/error/gateway_timeout.rb +10 -0
- data/lib/the_city/error/internal_server_error.rb +10 -0
- data/lib/the_city/error/not_acceptable.rb +10 -0
- data/lib/the_city/error/not_found.rb +10 -0
- data/lib/the_city/error/service_unavailable.rb +10 -0
- data/lib/the_city/error/too_many_requests.rb +12 -0
- data/lib/the_city/error/unauthorized.rb +10 -0
- data/lib/the_city/error/unprocessable_entity.rb +10 -0
- data/lib/the_city/error.rb +66 -0
- data/lib/the_city/event.rb +11 -0
- data/lib/the_city/group.rb +6 -0
- data/lib/the_city/need.rb +10 -0
- data/lib/the_city/permissions.rb +21 -0
- data/lib/the_city/prayer.rb +10 -0
- data/lib/the_city/rate_limit.rb +17 -0
- data/lib/the_city/terminology.rb +39 -0
- data/lib/the_city/time.rb +67 -0
- data/lib/the_city/token.rb +16 -0
- data/lib/the_city/topic.rb +10 -0
- data/lib/the_city/user.rb +41 -0
- data/lib/the_city/version.rb +18 -0
- data/lib/the_city.rb +15 -0
- data/thecity.gemspec +28 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e558202d2137889f1d2d101f981d0530ce7ba51
|
4
|
+
data.tar.gz: c0fa317f5e9b9a4df29c4c13c04befd2057917ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1526b289a4e20a8b9010cc2ee5d6b8cbf01890a817715881285aa8b1f432cb7400bb214e531dfdba30b2fd38af0a6152c40e7d2c72218be19074b939ff81faaf
|
7
|
+
data.tar.gz: 4fccefc74465b71e3eccd26ab290f149a08b4afe5df92c97dda35677a391be31e45f9583c18944c1c480b2e9f5e72f186dc18aa3aa94a10b099ccfec79a69473
|
data/CHANGELOG.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Copyright (c) 2013 Robert Leib
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
Portions of this software were inspired by, modeled after, or just plain copied from:
|
24
|
+
https://github.com/sferik/twitter
|
25
|
+
|
26
|
+
Copyright (c) 2006-2013 Erik Michaels-Ober, John Nunemaker, Wynn Netherland, Steve Richert, Steve Agalloco
|
27
|
+
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
29
|
+
a copy of this software and associated documentation files (the
|
30
|
+
"Software"), to deal in the Software without restriction, including
|
31
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
32
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
33
|
+
permit persons to whom the Software is furnished to do so, subject to
|
34
|
+
the following conditions:
|
35
|
+
|
36
|
+
The above copyright notice and this permission notice shall be
|
37
|
+
included in all copies or substantial portions of the Software.
|
38
|
+
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
40
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
41
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
42
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
43
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
44
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
45
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
# The City Ruby Gem
|
2
|
+
|
3
|
+
A Ruby interface to the The City API. For more information about The City platform, see [http://api.onthecity.org][api info]
|
4
|
+
|
5
|
+
[api info]: http://api.onthecity.org
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
gem install thecity
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
The City API requires you to authenticate via OAuth, so you'll need to
|
12
|
+
register your application with The City under the Admin | API panel.
|
13
|
+
|
14
|
+
Your new application will be assigned a key/secret pair (app_id/app_secret). You'll need
|
15
|
+
to configure these values before you make a request or else you'll get the
|
16
|
+
error:
|
17
|
+
|
18
|
+
Bad Authentication data
|
19
|
+
|
20
|
+
You can pass configuration options as a block to `TheCity::API::Client.new`.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
client = TheCity::API::Client.new do |config|
|
24
|
+
config.app_id = "YOUR_APP_ID"
|
25
|
+
config.app_secret = "YOUR_APP_SECRET"
|
26
|
+
config.access_token = "OAUTH_ACCESS_TOKEN"
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
or
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
client = TheCity::API::Client.new
|
34
|
+
client.app_id = "YOUR_APP_ID"
|
35
|
+
client.app_secret = "YOUR_APP_SECRET"
|
36
|
+
client.access_token = "OAUTH_ACCESS_TOKEN"
|
37
|
+
```
|
38
|
+
|
39
|
+
Alternately, you can set the following environment variables:
|
40
|
+
|
41
|
+
THECITY_APP_ID
|
42
|
+
THECITY_APP_SECRET
|
43
|
+
THECITY_ACCESS_TOKEN
|
44
|
+
THECITY_SUBDOMAIN
|
45
|
+
|
46
|
+
After configuration, requests can be made like so:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
client.current_user
|
50
|
+
```
|
51
|
+
|
52
|
+
or
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
client.my_groups
|
56
|
+
```
|
57
|
+
|
58
|
+
## Usage Examples
|
59
|
+
All examples require an authenticated TheCity client with a valid access_token. See the section on <a
|
60
|
+
href="#configuration">configuration</a>.
|
61
|
+
|
62
|
+
**Get the authenticated user (current user)**
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
client.me
|
66
|
+
```
|
67
|
+
**Post a topic**
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
client.post_topic(:group_id => 1234567, :title => 'Mr. Watson, come here', :body => 'I want to see you.')
|
71
|
+
```
|
72
|
+
**Fetch the groups the current user belongs to**
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
client.my_groups
|
76
|
+
```
|
77
|
+
**Retrieve the list of permissions associated with the current user**
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
client.followers("gem")
|
81
|
+
client.followers(213747670)
|
82
|
+
client.followers
|
83
|
+
```
|
84
|
+
**Fetch a cursored list of friends with profile details (by screen name or user ID, or by implict authenticated user)**
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
client.friends("gem")
|
88
|
+
client.friends(213747670)
|
89
|
+
client.friends
|
90
|
+
```
|
91
|
+
For more usage examples, please see the full [documentation][].
|
92
|
+
|
93
|
+
## Documentation
|
94
|
+
[http://rdoc.info/gems/thecity][documentation]
|
95
|
+
|
96
|
+
[documentation]: http://rdoc.info/gems/thecity
|
97
|
+
|
98
|
+
## Announcements
|
99
|
+
You should [follow @thecity][follow] [and @thecity_status][follow_status] on Twitter for announcements and updates about
|
100
|
+
this library.
|
101
|
+
|
102
|
+
[follow]: https://twitter.com/thecity
|
103
|
+
[follow_status]: https://twitter.com/thecity_status
|
104
|
+
|
105
|
+
## The City Builder API Developer Group
|
106
|
+
For more in depth discussiong regarding The City app platform and APIs, please join [the 'API' group on Builders][builders group].
|
107
|
+
|
108
|
+
[builders group]: https://builders.onthecity.org/groups/api
|
109
|
+
|
110
|
+
## Apps Wiki
|
111
|
+
Does your church or organization use this gem? Add it to the [apps
|
112
|
+
wiki][apps]!
|
113
|
+
|
114
|
+
[apps]: https://github.com/robertleib/thecity/wiki/apps
|
115
|
+
|
116
|
+
## Advanced Configuration
|
117
|
+
|
118
|
+
### Middleware
|
119
|
+
The Faraday middleware stack is fully configurable and is exposed as a
|
120
|
+
`Faraday::Builder` object. You can modify the default middleware in-place:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
client.middleware.insert_after TheCity::Response::RaiseError, CustomMiddleware
|
124
|
+
```
|
125
|
+
|
126
|
+
A custom adapter may be set as part of a custom middleware stack:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
client.middleware = Faraday::Builder.new(
|
130
|
+
&Proc.new do |builder|
|
131
|
+
# Specify a middleware stack here
|
132
|
+
builder.adapter :some_other_adapter
|
133
|
+
end
|
134
|
+
)
|
135
|
+
```
|
136
|
+
|
137
|
+
## Contributing to thecity gem
|
138
|
+
|
139
|
+
### Submitting an Issue
|
140
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
141
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
142
|
+
already been submitted. When submitting a bug report, please include a [Gist][]
|
143
|
+
that includes a stack trace and any details that may be necessary to reproduce
|
144
|
+
the bug, including your gem version, Ruby version, and operating system.
|
145
|
+
Ideally, a bug report should include a pull request with failing specs.
|
146
|
+
|
147
|
+
[issues]: https://github.com/robertleib/thecity/issues
|
148
|
+
[gist]: https://gist.github.com/
|
149
|
+
|
150
|
+
### Submitting a Pull Request
|
151
|
+
1. [Fork the repository.][fork]
|
152
|
+
2. [Create a topic branch.][branch]
|
153
|
+
3. Preferably, add specs for your unimplemented feature or bug fix.
|
154
|
+
4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
|
155
|
+
5. Implement your feature or bug fix.
|
156
|
+
6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
|
157
|
+
7. Add documentation for your feature or bug fix.
|
158
|
+
8. Run `bundle exec rake yard`.
|
159
|
+
9. Commit and push your changes.
|
160
|
+
10. [Submit a pull request.][pr]
|
161
|
+
|
162
|
+
[fork]: http://help.github.com/fork-a-repo/
|
163
|
+
[branch]: http://learn.github.com/p/branching.html
|
164
|
+
[pr]: http://help.github.com/send-pull-requests/
|
165
|
+
|
166
|
+
## Copyright
|
167
|
+
Copyright (c) 2013 Robert Leib.
|
168
|
+
See [LICENSE][] for details.
|
169
|
+
|
170
|
+
[license]: LICENSE.md
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module TheCity
|
2
|
+
# The City church account
|
3
|
+
#
|
4
|
+
# @!attribute [r] name
|
5
|
+
# @return [String] The name of the church, 'Grace Church'.
|
6
|
+
# @!attribute [r] subdomain
|
7
|
+
# @return [String] The subdomain used to access this account, subdomain.onthecity.org
|
8
|
+
# @!attribute [r] id
|
9
|
+
# @return [Integer] The id associated with the church account
|
10
|
+
|
11
|
+
class Account < TheCity::Base
|
12
|
+
attr_reader :name, :id, :subdomain
|
13
|
+
object_attr_reader :Terminology, :terminology
|
14
|
+
|
15
|
+
def initialize(attrs={}, options={})
|
16
|
+
super(attrs,options)
|
17
|
+
@campuses = Array(attrs.delete(:campuses)).map {|g| TheCity::Group.new(g,options)}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return campuses that belong to a multisite church
|
21
|
+
#
|
22
|
+
# @return [Array<TheCity::Group>]
|
23
|
+
def campuses
|
24
|
+
@campuses
|
25
|
+
end
|
26
|
+
|
27
|
+
def label_for(thecity_primitive)
|
28
|
+
terminology.send(thecity_primitive.downcase.to_sym)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'the_city/arguments'
|
2
|
+
require 'the_city/api/utils'
|
3
|
+
require 'the_city/account'
|
4
|
+
|
5
|
+
module TheCity
|
6
|
+
module API
|
7
|
+
module Accounts
|
8
|
+
include TheCity::API::Utils
|
9
|
+
|
10
|
+
# Returns the current City account associated with the current user
|
11
|
+
#
|
12
|
+
# @req_scope none
|
13
|
+
# @return [TheCity::Account]
|
14
|
+
# @param options [Hash] A customizable set of options.
|
15
|
+
def church_account(options={})
|
16
|
+
@church_account = nil if options.delete(:force_download)
|
17
|
+
@church_account ||= object_from_response(TheCity::Account, :get, "/church_account", options)
|
18
|
+
end
|
19
|
+
alias current_account church_account
|
20
|
+
alias current_church church_account
|
21
|
+
|
22
|
+
# Returns an array of all the City accounts associated with the current user
|
23
|
+
#
|
24
|
+
# @req_scope none
|
25
|
+
# @return [Array<TheCity::Account>]
|
26
|
+
# @param options [Hash] A customizable set of options.
|
27
|
+
def my_accounts(options={})
|
28
|
+
@my_accounts = nil if options.delete(:force_download)
|
29
|
+
@my_accounts ||= objects_from_response(TheCity::Account, :get, "/me/accounts", options)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday/request/multipart'
|
4
|
+
require 'json'
|
5
|
+
require 'the_city/client'
|
6
|
+
require 'the_city/error'
|
7
|
+
require 'the_city/error/configuration_error'
|
8
|
+
require 'the_city/api/request/multipart_with_file'
|
9
|
+
require 'the_city/api/response/parse_json'
|
10
|
+
require 'the_city/api/response/raise_error'
|
11
|
+
|
12
|
+
#require 'the_city/api/oauth'
|
13
|
+
require 'the_city/api/users'
|
14
|
+
require 'the_city/api/accounts'
|
15
|
+
require 'the_city/api/groups'
|
16
|
+
require 'the_city/api/topics'
|
17
|
+
require 'the_city/api/events'
|
18
|
+
require 'the_city/api/prayers'
|
19
|
+
require 'the_city/api/needs'
|
20
|
+
|
21
|
+
module TheCity
|
22
|
+
module API
|
23
|
+
# Wrapper for the TheCity REST API
|
24
|
+
#
|
25
|
+
# @see http://api.onthecity.com/docs
|
26
|
+
class Client < TheCity::Client
|
27
|
+
#include TheCity::API::OAuth
|
28
|
+
include TheCity::API::Users
|
29
|
+
include TheCity::API::Accounts
|
30
|
+
include TheCity::API::Groups
|
31
|
+
include TheCity::API::Topics
|
32
|
+
include TheCity::API::Events
|
33
|
+
include TheCity::API::Prayers
|
34
|
+
include TheCity::API::Needs
|
35
|
+
|
36
|
+
attr_writer :bearer_token, :connection_options, :middleware
|
37
|
+
|
38
|
+
ENDPOINT = ENV['THECITY_API_ENDPOINT'] || 'https://api.onthecity.org'
|
39
|
+
|
40
|
+
def connection_options
|
41
|
+
{
|
42
|
+
:builder => middleware,
|
43
|
+
:headers => {
|
44
|
+
:accept => "application/vnd.thecity.v#{version}+json",
|
45
|
+
'X-THECITY-SUBDOMAIN' => subdomain,
|
46
|
+
'X-THECITY-ACCESS-TOKEN' => access_token,
|
47
|
+
},
|
48
|
+
:request => {
|
49
|
+
:open_timeout => 5,
|
50
|
+
:timeout => 60,
|
51
|
+
},
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# @note Faraday's middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one.
|
56
|
+
# @see https://github.com/technoweenie/faraday#advanced-middleware-usage
|
57
|
+
# @see http://mislav.uniqpath.com/2011/07/faraday-advanced-http/
|
58
|
+
# @return [Faraday::Builder]
|
59
|
+
def middleware
|
60
|
+
@middleware ||= Faraday::Builder.new do |builder|
|
61
|
+
# Convert file uploads to Faraday::UploadIO objects
|
62
|
+
builder.use TheCity::API::Request::MultipartWithFile
|
63
|
+
# Checks for files in the payload
|
64
|
+
builder.use Faraday::Request::Multipart
|
65
|
+
# Convert request params to "www-form-urlencoded"
|
66
|
+
builder.use Faraday::Request::UrlEncoded
|
67
|
+
# Handle error responses
|
68
|
+
builder.use TheCity::API::Response::RaiseError
|
69
|
+
# Parse JSON response bodies
|
70
|
+
builder.use TheCity::API::Response::ParseJson
|
71
|
+
# Set Faraday's HTTP adapter
|
72
|
+
builder.adapter Faraday.default_adapter
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Perform an HTTP DELETE request
|
77
|
+
def delete(path, params={})
|
78
|
+
request(:delete, path, params)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Perform an HTTP GET request
|
82
|
+
def get(path, params={})
|
83
|
+
request(:get, path, params)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Perform an HTTP POST request
|
87
|
+
def post(path, params={})
|
88
|
+
signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params
|
89
|
+
request(:post, path, params, signature_params)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Perform an HTTP PUT request
|
93
|
+
def put(path, params={})
|
94
|
+
request(:put, path, params)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
# Returns a proc that can be used to setup the Faraday::Request headers
|
101
|
+
#
|
102
|
+
# @param method [Symbol]
|
103
|
+
# @param path [String]
|
104
|
+
# @param params [Hash]
|
105
|
+
# @return [Proc]
|
106
|
+
def request_setup(method, path, params, signature_params)
|
107
|
+
Proc.new do |request|
|
108
|
+
request.headers[:authorization] = bearer_auth_header
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def request(method, path, params={}, signature_params=params)
|
113
|
+
validate_credentials!
|
114
|
+
request_setup = request_setup(method, path, params, signature_params)
|
115
|
+
connection.send(method.to_sym, path, params, &request_setup).env
|
116
|
+
rescue Faraday::Error::ClientError, JSON::ParserError
|
117
|
+
raise TheCity::Error
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns a Faraday::Connection object
|
121
|
+
#
|
122
|
+
# @return [Faraday::Connection]
|
123
|
+
def connection
|
124
|
+
@connection ||= Faraday.new(ENDPOINT, connection_options)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Generates authentication header for api request
|
128
|
+
#
|
129
|
+
# @return [String]
|
130
|
+
def bearer_auth_header
|
131
|
+
"Bearer #{access_token}"
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'the_city/arguments'
|
2
|
+
require 'the_city/api/utils'
|
3
|
+
require 'the_city/event'
|
4
|
+
|
5
|
+
module TheCity
|
6
|
+
module API
|
7
|
+
module Events
|
8
|
+
include TheCity::API::Utils
|
9
|
+
|
10
|
+
# Posts an Event to The City
|
11
|
+
#
|
12
|
+
# @see https://api.onthecity.org/docs
|
13
|
+
#
|
14
|
+
# @req_scope group_content
|
15
|
+
# @return [TheCity::Event]
|
16
|
+
# @param options [Hash] A customizable set of options.
|
17
|
+
# @option options [Integer] :group_id The id of the group you will be posting to.
|
18
|
+
# @option options [String] :title The title of the event.
|
19
|
+
# @option options [String] :body The body text of the event.
|
20
|
+
# @option options [Time] :starting_at The body text of the event.
|
21
|
+
# @option options [Time] :ending_at The body text of the event.
|
22
|
+
def post_event(options)
|
23
|
+
raise(Error::ArgumentError, "Must supply a options[:group_id] for the events's originating group") unless options[:group_id]
|
24
|
+
raise(Error::ArgumentError, "Title (options[:title]) required") unless options[:title]
|
25
|
+
raise(Error::ArgumentError, "Body (options[:body]) required") unless options[:body]
|
26
|
+
raise(Error::ArgumentError, "Starting At (options[:starting_at]) required") unless options[:starting_at]
|
27
|
+
raise(Error::ArgumentError, "Ending At (options[:ending_at]) required") unless options[:ending_at]
|
28
|
+
gid = options[:group_id] || 0
|
29
|
+
object_from_response(TheCity::Event, :post, "/groups/#{gid}/events/", options, {:client => self})
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns an Event by id
|
33
|
+
#
|
34
|
+
# @see https://api.onthecity.org/docs
|
35
|
+
#
|
36
|
+
# @req_scope group_content
|
37
|
+
# @return [TheCity::Event]
|
38
|
+
# @raise [TheCity::Error::NotFound] Error raised when the event cannot be found.
|
39
|
+
# @overload event(id)
|
40
|
+
# @param id [Integer] The id of the event.
|
41
|
+
# @overload event(id, options={})
|
42
|
+
# @param id [Integer] The id of the event.
|
43
|
+
# @param options [Hash] A customizable set of options.
|
44
|
+
# @option options [Boolean] :force_download Forces the request to hit the server and flush the cached response
|
45
|
+
def event(*args)
|
46
|
+
@events ||= {}
|
47
|
+
arguments = TheCity::Arguments.new(args)
|
48
|
+
eid = args.shift
|
49
|
+
@events[eid] = nil if arguments.options.delete(:force_download)
|
50
|
+
@events[eid] ||= object_from_response(TheCity::Event, :get, "/events/#{eid}", arguments.options, {:client => self})
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'the_city/arguments'
|
2
|
+
require 'the_city/api/utils'
|
3
|
+
|
4
|
+
module TheCity
|
5
|
+
module API
|
6
|
+
module Groups
|
7
|
+
include TheCity::API::Utils
|
8
|
+
|
9
|
+
# Returns all the groups that the current user has an active role in
|
10
|
+
#
|
11
|
+
# @req_scope group_contont or user_groups
|
12
|
+
# @param options [Hash] A customizable set of options.
|
13
|
+
# @option options [Boolean] :force_download Forces the request to hit the server and flush the cached response
|
14
|
+
# @return [Array<TheCity::Group>]
|
15
|
+
def my_groups(options={})
|
16
|
+
@my_groups = nil if options.delete(:force_download)
|
17
|
+
@my_groups ||= objects_from_response(TheCity::Group, :get, "/me/groups", options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a group by id
|
21
|
+
#
|
22
|
+
# @req_scope group_trusted
|
23
|
+
# @return [TheCity::Group]
|
24
|
+
# @raise [TheCity::Error::NotFound] Error raised when the group cannot be found.
|
25
|
+
# @overload group(id)
|
26
|
+
# @param id [Integer] The id of the group.
|
27
|
+
# @overload group(id, options={})
|
28
|
+
# @param id [Integer] The id of the group.
|
29
|
+
# @param options [Hash] A customizable set of options.
|
30
|
+
# @option options [Boolean] :force_download Forces the request to hit the server and flush the cached response
|
31
|
+
def group(*args)
|
32
|
+
@groups ||= {}
|
33
|
+
arguments = TheCity::Arguments.new(args)
|
34
|
+
gid = args.shift
|
35
|
+
@groups[tid] = nil if arguments.options.delete(:force_download)
|
36
|
+
@groups[tid] ||= object_from_response(TheCity::Group, :get, "/groups/#{gid}", arguments.options)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'the_city/arguments'
|
2
|
+
require 'the_city/api/utils'
|
3
|
+
require 'the_city/need'
|
4
|
+
|
5
|
+
module TheCity
|
6
|
+
module API
|
7
|
+
module needs
|
8
|
+
include TheCity::API::Utils
|
9
|
+
|
10
|
+
# Posts a need to The City
|
11
|
+
#
|
12
|
+
# @see https://api.onthecity.org/docs
|
13
|
+
#
|
14
|
+
# @req_scope group_content
|
15
|
+
# @return [TheCity::Need]
|
16
|
+
# @param options [Hash] A customizable set of options.
|
17
|
+
# @option options [Integer] :group_id The id of the group you will be posting to.
|
18
|
+
# @option options [String] :title The title of the need.
|
19
|
+
# @option options [String] :body The body text of the need.
|
20
|
+
def post_need(options)
|
21
|
+
raise(Error::ArgumentError, "Must supply a options[:group_id] for the needs's originating group") unless options[:group_id]
|
22
|
+
raise(Error::ArgumentError, "Title (options[:title]) required") unless options[:title]
|
23
|
+
raise(Error::ArgumentError, "Body (options[:body]) required") unless options[:body]
|
24
|
+
gid = options[:group_id] || 0
|
25
|
+
object_from_response(TheCity::Need, :post, "/groups/#{gid}/needs/", options, {:client => self})
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a need by id
|
29
|
+
#
|
30
|
+
# @see https://api.onthecity.org/docs
|
31
|
+
#
|
32
|
+
# @req_scope group_content
|
33
|
+
# @return [TheCity::Need]
|
34
|
+
# @raise [TheCity::Error::NotFound] Error raised when the need cannot be found.
|
35
|
+
# @overload need(id)
|
36
|
+
# @param id [Integer] The id of the need.
|
37
|
+
# @overload need(id, options={})
|
38
|
+
# @param id [Integer] The id of the need.
|
39
|
+
# @param options [Hash] A customizable set of options.
|
40
|
+
# @option options [Boolean] :force_download Forces the request to hit the server and flush the cached response
|
41
|
+
def need(*args)
|
42
|
+
@needs ||= {}
|
43
|
+
arguments = TheCity::Arguments.new(args)
|
44
|
+
nid = args.shift
|
45
|
+
@needs[nid] = nil if arguments.options.delete(:force_download)
|
46
|
+
@needs[nid] ||= object_from_response(TheCity::Need, :get, "/needs/#{nid}", arguments.options, {:client => self})
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'the_city/api/utils'
|
2
|
+
require 'the_city/token'
|
3
|
+
|
4
|
+
module TheCity
|
5
|
+
module API
|
6
|
+
module OAuth
|
7
|
+
include TheCity::API::Utils
|
8
|
+
|
9
|
+
def authentication_url
|
10
|
+
"https://authentication.onthecity.org/oauth/authorize?#{authentication_headers}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def authentication_headers
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def authentication_params
|
18
|
+
"scope=user_basic&app_id="
|
19
|
+
end
|
20
|
+
|
21
|
+
def authorization_url(code)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Allows a registered application to obtain an OAuth 2 Bearear Token, which can be used to make API requests
|
25
|
+
# on an application's own behalf, without a user context.
|
26
|
+
#
|
27
|
+
# Only one bearer token may exist outstanding for an application, and repeated requests to this method
|
28
|
+
# will yield the same already-existent token until it has been invalidated.
|
29
|
+
#
|
30
|
+
# @return [TheCity::Token] The Bearer Token. token_type should be 'bearer'.
|
31
|
+
# @example Generate a Bearer Token
|
32
|
+
# client = TheCity::API::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
|
33
|
+
# bearer_token = client.token
|
34
|
+
def token
|
35
|
+
object_from_response(TheCity::Token, :post, "/oauth2/token", :grant_type => "client_credentials", :bearer_token_request => true)
|
36
|
+
end
|
37
|
+
alias bearer_token token
|
38
|
+
|
39
|
+
# Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
|
40
|
+
#
|
41
|
+
# @param access_token [String, TheCity::Token] The bearer token to revoke.
|
42
|
+
# @return [TheCity::Token] The invalidated token. token_type should be nil.
|
43
|
+
def invalidate_token(access_token)
|
44
|
+
access_token = access_token.access_token if access_token.is_a?(TheCity::Token)
|
45
|
+
object_from_response(TheCity::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|