thecity 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/the_city/account.rb +1 -1
- data/lib/the_city/api/groups.rb +1 -1
- data/lib/the_city/content.rb +3 -4
- data/lib/the_city/group.rb +1 -1
- data/lib/the_city/permissions.rb +8 -0
- data/lib/the_city/topic.rb +4 -0
- data/lib/the_city/user.rb +59 -16
- data/lib/the_city/version.rb +1 -1
- data/spec/helper.rb +65 -35
- data/spec/thecity/user_spec.rb +1 -1
- metadata +2 -6
- data/lib/the_city/api/oauth.rb +0 -50
- data/lib/the_city/token.rb +0 -16
- data/spec/thecity/api/users_spec.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d34152f9f12969373d5f5eb2be4b02356ade4ffd
|
4
|
+
data.tar.gz: 693564268d37117d9f619b83998f872912262350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 426501071ad8fd11f5cd1842799f2aa9b360607e30dbb2f6076af0cb38605316a5b6ac36cfa5439848510c9b66b796ac2078e0f85b5f9c66d36a61e201f7d92f
|
7
|
+
data.tar.gz: 31ee55ad21b32d3d007cafe9c38f8a695567af5a17e31ed65cbbefd05a596f4cbabe9397c4a1d2bbc111f2600b8320989995dc80fedc1bea64254cd3694afa91
|
data/lib/the_city/account.rb
CHANGED
data/lib/the_city/api/groups.rb
CHANGED
@@ -8,7 +8,7 @@ module TheCity
|
|
8
8
|
|
9
9
|
# Returns all the groups that the current user has an active role in
|
10
10
|
#
|
11
|
-
# @req_scope
|
11
|
+
# @req_scope group_content or user_groups
|
12
12
|
# @param options [Hash] A customizable set of options.
|
13
13
|
# @option options [Boolean] :force_download Forces the request to hit the server and flush the cached response
|
14
14
|
# @return [Array<TheCity::Group>]
|
data/lib/the_city/content.rb
CHANGED
@@ -16,13 +16,12 @@ module TheCity
|
|
16
16
|
|
17
17
|
class Content < TheCity::Base
|
18
18
|
include TheCity::Time
|
19
|
-
attr_reader :id, :title, :body
|
19
|
+
attr_reader :id, :title, :body, :blurb, :group_id,
|
20
|
+
:leader_only, :priority, :member_only, :gender_only, :gender_only_gender, :featured,
|
21
|
+
:short_url, :file_attachments, :plaza, :shareable, :address
|
20
22
|
object_attr_reader :User, :user
|
21
23
|
object_attr_reader :Group, :group
|
22
24
|
|
23
|
-
# def user
|
24
|
-
# @user
|
25
|
-
# end
|
26
25
|
alias author user
|
27
26
|
|
28
27
|
end
|
data/lib/the_city/group.rb
CHANGED
data/lib/the_city/permissions.rb
CHANGED
@@ -17,5 +17,13 @@ module TheCity
|
|
17
17
|
class Permissions < TheCity::Base
|
18
18
|
attr_reader :can_list_in_plaza, :member, :staff, :admin, :can_create_in_group_ids, :admin_privileges
|
19
19
|
|
20
|
+
def is_account_admin?
|
21
|
+
admin_privileges.any? {|ap| ap[:title] == 'Account Admin'} rescue false
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_user_admin?
|
25
|
+
admin_privileges.any? {|ap| ap[:title] == 'User Admin'} rescue false
|
26
|
+
end
|
27
|
+
|
20
28
|
end
|
21
29
|
end
|
data/lib/the_city/topic.rb
CHANGED
data/lib/the_city/user.rb
CHANGED
@@ -1,23 +1,56 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
1
3
|
module TheCity
|
2
4
|
class User < TheCity::Base
|
3
|
-
|
4
|
-
|
5
|
-
attr_reader :id, :name, :profile_picture, :gender
|
5
|
+
attr_reader :id, :title, :first, :last, :name, :profile_picture, #user_basic
|
6
|
+
:gender, :email ##user_extended
|
6
7
|
attr_writer :permissions
|
7
8
|
|
8
|
-
def_delegators :@permissions, :member?, :staff?, :admin?
|
9
|
-
|
10
9
|
# Returns the groups that the user belongs to
|
11
10
|
#
|
12
11
|
# @return [Array<TheCity::Group>]
|
13
12
|
def groups
|
14
13
|
memoize(:groups) do
|
15
|
-
|
16
|
-
|
14
|
+
if @attrs[:groups].any?
|
15
|
+
Array(@attrs[:groups]).map do |g|
|
16
|
+
TheCity::Group.new(g)
|
17
|
+
end
|
18
|
+
elsif @client
|
19
|
+
@client.my_groups
|
20
|
+
else
|
21
|
+
[]
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
26
|
+
def method_missing(method_sym, *arguments, &block)
|
27
|
+
if method_sym.to_s =~ /^is_in_group_(\d+)\??$/
|
28
|
+
is_in_group_with_title?($1.to_i, arguments.first)
|
29
|
+
else
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @note Returns true/false if the current user has an active role in the group (group_id).
|
35
|
+
#
|
36
|
+
# @param group_id [Integer] the id of TheCity::Group in question.
|
37
|
+
# @param title [Array<String>] the title or titles of the user's active role.
|
38
|
+
# @example see if the user is a leader in group 1234
|
39
|
+
# current_user.is_in_group_with_title(1234, :leader)
|
40
|
+
# @return [Boolean]
|
41
|
+
def is_in_group_with_title?(group_id, title=nil)
|
42
|
+
return groups.any? {|g| g.id == group_id } if title.nil?
|
43
|
+
titles = [title].flatten
|
44
|
+
return groups.any? {|g| (g.id == group_id and titles.any? {|t| t.to_s.downcase == g.role_title.downcase } ) }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns the user's birthdate as a ruby Date object.
|
48
|
+
#
|
49
|
+
# @return [Date]
|
50
|
+
def birthdate
|
51
|
+
@bday ||= Date.strptime(@attrs[:birthdate], '%m/%d/%Y') rescue nil
|
52
|
+
end
|
53
|
+
|
21
54
|
# Returns the permissions for the current user
|
22
55
|
#
|
23
56
|
# @return [TheCity::Permissions]
|
@@ -25,17 +58,27 @@ module TheCity
|
|
25
58
|
@permissions ||= @client.permissions if (@client and @client.current_user.id == id)
|
26
59
|
end
|
27
60
|
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
61
|
+
# Returns true/false if the current user is an admin on the current church (Group Admin, Account Admin, etc).
|
62
|
+
# If you need to check for a specific admin privilege, you will need to go through TheCity::Permissions object.
|
63
|
+
#
|
64
|
+
# @return [Boolean]
|
65
|
+
def admin?
|
66
|
+
@attrs[:admin] || permissions.admin? rescue nil
|
67
|
+
end
|
31
68
|
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
69
|
+
# Returns true/false if the current user is a member of the current church.
|
70
|
+
#
|
71
|
+
# @return [Boolean]
|
72
|
+
def member?
|
73
|
+
@attrs[:member] || permissions.member? rescue nil
|
74
|
+
end
|
35
75
|
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
76
|
+
# Returns true/false if the current user is on staff at the current church.
|
77
|
+
#
|
78
|
+
# @return [Boolean]
|
79
|
+
def staff?
|
80
|
+
@attrs[:staff] || permissions.staff? rescue nil
|
81
|
+
end
|
39
82
|
|
40
83
|
end
|
41
84
|
end
|
data/lib/the_city/version.rb
CHANGED
data/spec/helper.rb
CHANGED
@@ -11,8 +11,16 @@ SimpleCov.start
|
|
11
11
|
require 'the_city'
|
12
12
|
require 'rspec'
|
13
13
|
require 'webmock/rspec'
|
14
|
+
require 'vcr'
|
15
|
+
require 'typhoeus'
|
16
|
+
require 'active_support/core_ext'
|
14
17
|
|
15
|
-
|
18
|
+
VCR.configure do |c|
|
19
|
+
c.cassette_library_dir = "spec/vcr_cassettes"
|
20
|
+
c.hook_into :webmock
|
21
|
+
c.default_cassette_options = {:re_record_interval => 7.days}
|
22
|
+
c.configure_rspec_metadata!
|
23
|
+
end
|
16
24
|
|
17
25
|
RSpec.configure do |config|
|
18
26
|
config.expect_with :rspec do |c|
|
@@ -20,42 +28,64 @@ RSpec.configure do |config|
|
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
23
|
-
def a_delete(path)
|
24
|
-
a_request(:delete, TheCity::API::Client::ENDPOINT + path)
|
25
|
-
end
|
26
31
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def stub_delete(path)
|
40
|
-
stub_request(:delete, TheCity::API::Client::ENDPOINT + path)
|
41
|
-
end
|
42
|
-
|
43
|
-
def stub_get(path)
|
44
|
-
stub_request(:get, TheCity::API::Client::ENDPOINT + path)
|
45
|
-
end
|
46
|
-
|
47
|
-
def stub_post(path)
|
48
|
-
stub_request(:post, TheCity::API::Client::ENDPOINT + path)
|
49
|
-
end
|
50
|
-
|
51
|
-
def stub_put(path)
|
52
|
-
stub_request(:put, TheCity::API::Client::ENDPOINT + path)
|
32
|
+
def get_oauth_token_for(username, password, subdomain='')
|
33
|
+
auth_response = Typhoeus.post("https://authentication.onthecity.org/",
|
34
|
+
:params => {"app_id" => APP_ID, "secret" => SECRET, "login" => username, "password" => password, "subdomain" => subdomain})
|
35
|
+
typhoeus_token = JSON.parse(auth_response.options[:response_body])['access_token']['token'] rescue nil
|
36
|
+
vcr_token = JSON.parse(auth_response.options[:body])['access_token']['token'] rescue nil
|
37
|
+
if typhoeus_token.nil?
|
38
|
+
return vcr_token
|
39
|
+
else
|
40
|
+
return typhoeus_token
|
41
|
+
end
|
53
42
|
end
|
54
43
|
|
55
|
-
def
|
56
|
-
|
44
|
+
def fire_up_test_client(subdomain='')
|
45
|
+
ENV['THECITY_SUBDOMAIN'] = subdomain
|
46
|
+
client = TheCity::API::Client.new do |config|
|
47
|
+
config.app_id = APP_ID
|
48
|
+
config.app_secret = SECRET
|
49
|
+
end
|
50
|
+
return client
|
57
51
|
end
|
58
52
|
|
59
|
-
def
|
60
|
-
|
61
|
-
end
|
53
|
+
#def a_delete(path)
|
54
|
+
# a_request(:delete, TheCity::API::Client::ENDPOINT + path)
|
55
|
+
#end
|
56
|
+
#
|
57
|
+
#def a_get(path)
|
58
|
+
# a_request(:get, TheCity::API::Client::ENDPOINT + path)
|
59
|
+
#end
|
60
|
+
#
|
61
|
+
#def a_post(path)
|
62
|
+
# a_request(:post, TheCity::API::Client::ENDPOINT + path)
|
63
|
+
#end
|
64
|
+
#
|
65
|
+
#def a_put(path)
|
66
|
+
# a_request(:put, TheCity::API::Client::ENDPOINT + path)
|
67
|
+
#end
|
68
|
+
#
|
69
|
+
#def stub_delete(path)
|
70
|
+
# stub_request(:delete, TheCity::API::Client::ENDPOINT + path)
|
71
|
+
#end
|
72
|
+
#
|
73
|
+
#def stub_get(path)
|
74
|
+
# stub_request(:get, TheCity::API::Client::ENDPOINT + path)
|
75
|
+
#end
|
76
|
+
#
|
77
|
+
#def stub_post(path)
|
78
|
+
# stub_request(:post, TheCity::API::Client::ENDPOINT + path)
|
79
|
+
#end
|
80
|
+
#
|
81
|
+
#def stub_put(path)
|
82
|
+
# stub_request(:put, TheCity::API::Client::ENDPOINT + path)
|
83
|
+
#end
|
84
|
+
#
|
85
|
+
#def fixture_path
|
86
|
+
# File.expand_path("../fixtures", __FILE__)
|
87
|
+
#end
|
88
|
+
#
|
89
|
+
#def fixture(file)
|
90
|
+
# File.new(fixture_path + '/' + file)
|
91
|
+
#end
|
data/spec/thecity/user_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
require 'helper'
|
3
2
|
|
4
3
|
describe TheCity::User do
|
@@ -16,6 +15,7 @@ describe TheCity::User do
|
|
16
15
|
expect(user.groups.first).to be_a TheCity::Group
|
17
16
|
expect(user.groups.first.name).to eq("My Group")
|
18
17
|
end
|
18
|
+
|
19
19
|
it "is empty when not set" do
|
20
20
|
user = TheCity::User.new(:id => 6753948)
|
21
21
|
expect(user.groups).to be_empty
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Leib
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -104,7 +104,6 @@ files:
|
|
104
104
|
- lib/the_city/api/events.rb
|
105
105
|
- lib/the_city/api/groups.rb
|
106
106
|
- lib/the_city/api/needs.rb
|
107
|
-
- lib/the_city/api/oauth.rb
|
108
107
|
- lib/the_city/api/prayers.rb
|
109
108
|
- lib/the_city/api/request/multipart_with_file.rb
|
110
109
|
- lib/the_city/api/response/parse_json.rb
|
@@ -139,14 +138,12 @@ files:
|
|
139
138
|
- lib/the_city/rate_limit.rb
|
140
139
|
- lib/the_city/terminology.rb
|
141
140
|
- lib/the_city/time.rb
|
142
|
-
- lib/the_city/token.rb
|
143
141
|
- lib/the_city/topic.rb
|
144
142
|
- lib/the_city/user.rb
|
145
143
|
- lib/the_city/version.rb
|
146
144
|
- lib/the_city.rb
|
147
145
|
- spec/fixtures/me.json
|
148
146
|
- spec/helper.rb
|
149
|
-
- spec/thecity/api/users_spec.rb
|
150
147
|
- spec/thecity/base_spec.rb
|
151
148
|
- spec/thecity/user_spec.rb
|
152
149
|
- spec/thecity_spec.rb
|
@@ -177,7 +174,6 @@ summary: A Ruby interface to The City API.
|
|
177
174
|
test_files:
|
178
175
|
- spec/fixtures/me.json
|
179
176
|
- spec/helper.rb
|
180
|
-
- spec/thecity/api/users_spec.rb
|
181
177
|
- spec/thecity/base_spec.rb
|
182
178
|
- spec/thecity/user_spec.rb
|
183
179
|
- spec/thecity_spec.rb
|
data/lib/the_city/api/oauth.rb
DELETED
@@ -1,50 +0,0 @@
|
|
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
|
data/lib/the_city/token.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'the_city/base'
|
2
|
-
|
3
|
-
module TheCity
|
4
|
-
class Token < TheCity::Base
|
5
|
-
attr_reader :access_token, :token_type
|
6
|
-
alias to_s access_token
|
7
|
-
|
8
|
-
BEARER_TYPE = "bearer"
|
9
|
-
|
10
|
-
# @return [Boolean]
|
11
|
-
def bearer?
|
12
|
-
@attrs[:token_type] == BEARER_TYPE
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe TheCity::API::Users do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@client = TheCity::API::Client.new(:app_id => "CK", :app_secret => "CS", :access_token => "AT")
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "#me" do
|
10
|
-
before do
|
11
|
-
stub_get("/me").to_return(:body => fixture("me.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
12
|
-
end
|
13
|
-
it "requests the correct resource" do
|
14
|
-
@client.me
|
15
|
-
expect(a_get("/me")).to have_been_made
|
16
|
-
end
|
17
|
-
it "returns the requesting user" do
|
18
|
-
user = @client.me
|
19
|
-
expect(user).to be_a TheCity::User
|
20
|
-
expect(user.id).to eq(6753948)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|