the-city-admin 0.1.1 → 0.1.2

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.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- ZenTest (4.8.1)
5
- activesupport (3.2.6)
4
+ ZenTest (4.8.2)
5
+ activesupport (3.2.8)
6
6
  i18n (~> 0.6)
7
7
  multi_json (~> 1.0)
8
8
  archive-tar-minitar (0.5.2)
@@ -10,22 +10,23 @@ GEM
10
10
  ZenTest (>= 4.4.1)
11
11
  columnize (0.3.6)
12
12
  diff-lcs (1.1.3)
13
- factory_girl (3.5.0)
13
+ factory_girl (4.0.0)
14
14
  activesupport (>= 3.0.0)
15
- i18n (0.6.0)
16
- json (1.7.3)
15
+ ffi (1.1.5)
16
+ i18n (0.6.1)
17
+ json (1.7.5)
17
18
  linecache19 (0.5.12)
18
19
  ruby_core_source (>= 0.1.4)
19
- mime-types (1.18)
20
+ mime-types (1.19)
20
21
  multi_json (1.3.6)
21
- rspec (2.8.0)
22
- rspec-core (~> 2.8.0)
23
- rspec-expectations (~> 2.8.0)
24
- rspec-mocks (~> 2.8.0)
25
- rspec-core (2.8.0)
26
- rspec-expectations (2.8.0)
27
- diff-lcs (~> 1.1.2)
28
- rspec-mocks (2.8.0)
22
+ rspec (2.11.0)
23
+ rspec-core (~> 2.11.0)
24
+ rspec-expectations (~> 2.11.0)
25
+ rspec-mocks (~> 2.11.0)
26
+ rspec-core (2.11.1)
27
+ rspec-expectations (2.11.2)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.11.2)
29
30
  ruby-debug-base19 (0.11.25)
30
31
  columnize (>= 0.3.1)
31
32
  linecache19 (>= 0.5.11)
@@ -36,8 +37,9 @@ GEM
36
37
  ruby-debug-base19 (>= 0.11.19)
37
38
  ruby_core_source (0.1.5)
38
39
  archive-tar-minitar (>= 0.5.2)
39
- typhoeus (0.3.3)
40
- mime-types
40
+ typhoeus (0.4.2)
41
+ ffi (~> 1.0)
42
+ mime-types (~> 1.18)
41
43
 
42
44
  PLATFORMS
43
45
  ruby
data/index.rb CHANGED
@@ -8,116 +8,136 @@
8
8
  require 'ruby-debug'
9
9
  require File.dirname(__FILE__) + '/lib/the_city_admin.rb'
10
10
 
11
- # staging
12
- # key = 'bc6b57204b0ee4818bb4b3befd0f3292e93a2d0a'
13
- # token = '7cfed59b037125d3'
14
-
15
- # Local
16
- key = '66c59e2ee24553e7237259e30b4c17365681b95c'
17
- token = 'a9ae4af3c3e80102'
18
-
11
+ key = 'cf2903151e3213e66fd8080c7d8b65b1d6ccdd31'
12
+ token = '5c88b32edda7653c'
19
13
 
20
14
  TheCity::AdminApi.connect(key, token)
21
15
 
22
- ###### USERS / GROUPS #######
16
+ # puts "-----------------------------"
17
+ # puts "##### USERS #######"
18
+ # puts "-----------------------------"
23
19
 
24
- puts "-----------------------------"
25
20
 
26
- user = TheCity::User.new
27
- user.title = 'Deacon'
28
- user.first = 'James'
29
- user.middle = 'Wesley'
30
- user.last = 'Hays'
31
- user.nickname = 'Wes'
32
- user.gender = TheCity::User::Gender[:male]
33
- user.email = 'wes+tc6@onthecity.org'
34
- user.staff = false
35
- user.member_since = Time.now.strftime("%Y-%m-%d")
36
- user.birthdate = '1980-09-27'
37
- user.primary_phone = '775-745-3013'
38
- user.primary_phone_type = TheCity::User::PhoneType[:mobile]
39
- user.secondary_phone = '775-677-7707'
40
- user.secondary_phone_type = TheCity::User::PhoneType[:home]
41
- #user.marital_status = TheCity::User::MaritalStatus[:married]
42
- #user.primary_campus_id
43
- #user.external_id_1
44
- #user.external_id_2
45
- #user.external_id_3
46
- unless user.save
47
- user.error_messages.each { |em| puts em }
48
- end
49
-
50
- user.delete
21
+ # user_list = TheCity::UserList.new
51
22
 
23
+ # user_list.each do |u|
24
+ # puts u.full_name
25
+ # end
52
26
 
53
27
  # puts "-----------------------------"
54
28
 
29
+ # user = TheCity::User.new
30
+ # user.title = 'Deacon'
31
+ # user.first = 'James'
32
+ # user.middle = 'Wesley'
33
+ # user.last = 'Hays'
34
+ # user.nickname = 'Wes'
35
+ # user.gender = TheCity::User::Gender[:male]
36
+ # user.email = 'someguy@somewhere.org'
37
+ # user.staff = false
38
+ # user.member_since = Time.now.strftime("%Y-%m-%d")
39
+ # user.birthdate = '1980-09-27'
40
+ # user.primary_phone = '775-111-2222'
41
+ # user.primary_phone_type = TheCity::User::PhoneType[:mobile]
42
+ # user.secondary_phone = '775-333-4444'
43
+ # user.secondary_phone_type = TheCity::User::PhoneType[:home]
44
+ # user.marital_status = TheCity::User::MaritalStatus[:married]
45
+ # #user.primary_campus_id
46
+ # #user.external_id_1
47
+ # #user.external_id_2
48
+ # #user.external_id_3
49
+
50
+ # if user.save
51
+ # puts "User #{user.full_name} saved (#{user.id})"
52
+ # else
53
+ # user.error_messages.each { |em| puts em }
54
+ # end
55
55
 
56
- # user = the_city.users[0]
57
- # puts user.full_name
58
- # user.first = 'Wes'
59
- # puts user.full_name
60
- # user.save
61
- # puts user.id
62
- # user2 = TheCity::User.load_user_by_id(user.id)
63
- # puts user2.full_name
56
+ # user2 = TheCity::User.load_by_id(user.id)
57
+ # user2.email = 'somegirl@somewhere.org'
58
+ # user2.nickname = 'dog'
64
59
 
65
- # group = the_city.groups[0]
66
- # puts group.name
67
- # group.name = 'Wes Group'
68
- # puts group.name
69
- # group.save
70
- # group2 = TheCity::Group.load_group_by_id(group.id)
71
- # puts group2.name
60
+ # if user2.save
61
+ # puts "User #{user2.full_name} updated (#{user2.id})"
62
+ # else
63
+ # user2.error_messages.each { |em| puts em }
64
+ # end
72
65
 
66
+ # if user.delete
67
+ # puts "User #{user.full_name} deleted (#{user.id})"
68
+ # else
69
+ # puts "Something bad happened"
70
+ # #user.error_messages.each { |em| puts em }
71
+ # end
73
72
 
74
73
 
74
+ puts "-----------------------------"
75
75
 
76
- ###### USERS #######
76
+ user_list = TheCity::UserList.new
77
77
 
78
- # user = the_city.users[0]
79
- # puts user.full_name
78
+ user = user_list[0]
79
+ puts user.full_name
80
+ user.first = 'Wes'
81
+ puts user.full_name
82
+ user.save
83
+ puts user.id
80
84
 
85
+ user2 = TheCity::User.load_by_id(user.id)
86
+ puts user2.full_name
81
87
 
82
- # user2 = TheCity::User.load_user_by_id(1068169470) #(564114313)
83
- # puts user2.full_name
88
+ puts "User has #{user.addresses.size} addresses"
89
+ puts "User has #{user.family.size} family members"
90
+ puts "User has #{user.notes.size} notes"
91
+ puts "User has #{user.roles.size} roles"
92
+ puts "User has #{user.skills.size} skills"
93
+ #puts "User has #{user.processes.size} processes"
94
+ puts "User has #{user.invitations.size} invitations"
95
+ #puts "User has #{user.admin_privileges.size} admin_privileges"
84
96
 
85
- # user = the_city.users[1]
86
- # puts user.full_name
87
97
 
88
98
  # This is currenly returning a 404 if no family members are found
89
99
  # puts user.family[0].name
90
100
 
91
- # puts user.addresses[0].location_type
92
- # puts user.notes[0].author
93
- # puts user.roles[0].group_name
94
- # puts user.skills[0].name
95
- # puts user.processes[0].name
96
- # puts user.invitations[0].source
97
- # puts user.admin_privileges[0].title
98
101
 
99
102
 
100
- ###### GROUPS #######
103
+ # puts "-----------------------------"
101
104
 
102
- # group = the_city.groups[0]
105
+ # group_list = TheCity::GroupList.new
106
+ # group = group_list[0]
103
107
  # puts group.name
104
- # puts group.id
108
+ # group.name = 'Wes Group'
109
+ # puts group.name
110
+ # group.save
111
+ # group2 = TheCity::Group.load_by_id(group.id)
112
+ # puts group2.name
113
+
114
+
115
+ # # puts "-----------------------------"
116
+ # # puts "##### GROUPS #######"
117
+ # # puts "-----------------------------"
105
118
 
106
- # Fails with 500 error
107
- # puts group.addresses[0].location_type
119
+ # group_list = TheCity::GroupList.new
108
120
 
109
- # puts group.roles[0].user_name
110
- # puts group.tags[0].name
121
+ # group = group_list[13]
122
+ # puts "Group Name: #{group.name} (#{group.id})"
111
123
 
112
- # puts group.invitations[0].source
124
+ # if group.roles.size == 0
125
+ # puts "No group roles found"
126
+ # else
127
+ # puts group.roles[0].title
128
+ # end
113
129
 
114
- # metric = the_city.metrics[0]
130
+ # if group.tags.size == 0
131
+ # puts "No group tags found"
132
+ # else
133
+ # puts group.tags[0].name
134
+ # end
115
135
 
116
- # puts metric.name
117
- # metric.measurements.total_entries.times do |i|
118
- # puts "#{metric.measurements[i].created_at}: #{metric.measurements[i].value}"
136
+ # if group.invitations.size == 0
137
+ # puts "No group invitations found"
138
+ # else
139
+ # puts group.invitations[0].id
119
140
  # end
120
- # new_measurement = TheCity::MetricMeasurement.new(:id => metric.id, :value => 999)
121
- # new_measurement.save
141
+
122
142
 
123
143
 
data/lib/api/user.rb CHANGED
@@ -41,7 +41,8 @@ module TheCity
41
41
  :external_id_2,
42
42
  :external_id_3,
43
43
  :middle,
44
- :email
44
+ :email,
45
+ :marital_status
45
46
 
46
47
 
47
48
  # Loads the user by the specified ID.
data/lib/common.rb CHANGED
@@ -1,37 +1,23 @@
1
1
  module TheCity
2
2
  require 'cgi'
3
+ require 'json'
3
4
 
4
5
 
5
6
  def self.admin_request(method, path, params = {})
6
7
  headers = self._build_admin_headers(method, path, params)
7
8
  url = THE_CITY_ADMIN_PATH+path
8
9
 
9
- data_params = params.inject({}) {|h, (k,v)| h.update({k => v.nil? ? v : CGI.escape(v.to_s)})}
10
-
11
10
  response =
12
11
  case method
13
12
  when :post
14
- Typhoeus::Request.post(url, {:headers => headers, :params => self._flatten_params(data_params)})
13
+ Typhoeus::Request.post(url, {:headers => headers, :params => params})
15
14
  when :get
16
- Typhoeus::Request.get(url, {:headers => headers, :params => self._flatten_params(data_params)})
15
+ Typhoeus::Request.get(url, {:headers => headers, :params => params})
17
16
  when :put
18
- Typhoeus::Request.put(url, {:headers => headers, :params => self._flatten_params(data_params)})
17
+ Typhoeus::Request.put(url, {:headers => headers, :params => params})
19
18
  when :delete
20
- Typhoeus::Request.delete(url, {:headers => headers, :params => self._flatten_params(data_params)})
21
- end
22
-
23
- # unless response.success?
24
- # if response.curl_error_message != 'No error'
25
- # raise TheCityExceptions::UnableToConnectToTheCity.new(response.curl_error_message)
26
- # else
27
- # begin
28
- # raise TheCityExceptions::TheCityResponseError.new( JSON.parse(response.body)['error_message'] )
29
- # rescue
30
- # raise TheCityExceptions::UnknownErrorConnectingToTheCity.new('Unknown error when connecting to The City')
31
- # end
32
- # end
33
- # end
34
-
19
+ Typhoeus::Request.delete(url, {:headers => headers, :params => params})
20
+ end
35
21
 
36
22
  unless response.success?
37
23
  if response.curl_error_message != 'No error'
@@ -51,21 +37,9 @@ module TheCity
51
37
  end
52
38
 
53
39
 
54
- def self._flatten_params(params)
55
- retval = {}
56
- params.each do |key, value|
57
- if value.instance_of?(Array)
58
- value.each_with_index { |a_val, indx| retval["#{key}[#{indx}]"] = a_val }
59
- else # assume string
60
- retval[key] = value
61
- end
62
- end
63
- retval
64
- end
65
-
66
-
67
40
  def self._build_admin_headers(method, path, params)
68
- get_vars = '?' + params.to_a.sort.collect { |kv_pair| "#{kv_pair[0]}=#{kv_pair[1]}" }.join('&')
41
+ get_vars = method == :post ? '' : '?'
42
+ get_vars += params.to_a.sort.collect { |kv_pair| "#{kv_pair[0]}=#{kv_pair[1].to_s}" }.join('&')
69
43
  get_vars = '' if get_vars == '?'
70
44
  method_request = method.to_s.upcase
71
45
  url = THE_CITY_ADMIN_PATH + path + get_vars
@@ -75,141 +49,11 @@ module TheCity
75
49
  unescaped_hmac = Base64.encode64(unencoded_hmac).chomp
76
50
  hmac_signature = CGI.escape(unescaped_hmac)
77
51
 
78
- headers = {'X-City-Sig' => hmac_signature,
79
- 'X-City-User-Token' => TheCity::AdminApi::API_TOKEN,
80
- 'X-City-Time' => current_time,
81
- 'Accept' => 'application/vnd.thecity.admin.v1+json'}
82
-
83
-
84
- # This is causing issues.... not sure if it is needed (docs might be lieing)
85
- # if [:post, :put].include?(method)
86
- # headers['Content-Type'] = 'application/json'
87
- # headers['Content-Length'] = params.to_json.length
88
- # end
89
-
90
- headers
52
+ {'X-City-Sig' => hmac_signature,
53
+ 'X-City-User-Token' => TheCity::AdminApi::API_TOKEN,
54
+ 'X-City-Time' => current_time,
55
+ 'Accept' => 'application/vnd.thecity.admin.v1+json',
56
+ 'Content-Type' => 'application/json'}
91
57
  end
92
58
 
93
-
94
-
95
- # def self.admin_request(method, path, params = {})
96
- # # data_params = params.inject({}) {|h, (k,v)| h.update({k => v.nil? ? v : v.to_s})}
97
- # # flattened_params = self._flatten_params(data_params)
98
-
99
- # flattened_params = self._flatten_params(params)
100
-
101
- # # puts "############################"
102
- # # puts "flattened_params: #{flattened_params}"
103
- # # puts "############################"
104
-
105
- # headers = self._build_admin_headers(method, path, flattened_params)
106
- # url = THE_CITY_ADMIN_PATH+path
107
-
108
- # response =
109
- # case method
110
- # when :post
111
- # Typhoeus::Request.post(url, {:headers => headers, :params => flattened_params})
112
- # when :get
113
- # Typhoeus::Request.get(url, {:headers => headers, :params => flattened_params})
114
- # when :put
115
- # Typhoeus::Request.put(url, {:headers => headers, :params => flattened_params})
116
- # when :delete
117
- # Typhoeus::Request.delete(url, {:headers => headers, :params => flattened_params})
118
- # end
119
-
120
- # unless response.success?
121
- # if response.curl_error_message != 'No error'
122
- # raise TheCityExceptions::UnableToConnectToTheCity.new(response.curl_error_message)
123
- # else
124
- # begin
125
- # error_messages = JSON.parse(response.body)['error_message']
126
- # rescue
127
- # raise TheCityExceptions::UnknownErrorConnectingToTheCity.new('Unknown error when connecting to The City')
128
- # else
129
- # raise TheCityExceptions::TheCityResponseError.new(error_messages)
130
- # end
131
- # end
132
- # end
133
-
134
- # response
135
- # end
136
-
137
-
138
- # def self._flatten_params(params, prefix='')
139
- # retval = []
140
- # if params.instance_of?(Array)
141
- # if params.empty?
142
- # retval << self._flatten_params('', "#{prefix.to_s}[0]")
143
- # else
144
- # params.each_with_index do |value, indx|
145
- # retval << self._flatten_params(value, "#{prefix.to_s}[#{indx}]")
146
- # end
147
- # end
148
- # elsif params.instance_of?(Hash)
149
- # params.each do |key, value|
150
- # retval << self._flatten_params(value, prefix.empty? ? key.to_s : "#{prefix}[#{key.to_s}]")
151
- # end
152
- # else # assume string
153
- # retval << "#{prefix}=#{params}"
154
- # end
155
-
156
- # if prefix.empty?
157
- # hvals = {}
158
- # retval.flatten.sort.each { |v| hvals[v.split('=')[0]] = v.split('=')[1] }
159
- # hvals
160
- # else
161
- # retval.flatten.sort
162
- # end
163
- # #retval.flatten.sort
164
- # end
165
-
166
-
167
-
168
- # def self._build_admin_headers(method, path, params)
169
- # # get_vars = '?' + params.to_a.sort.collect { |kv_pair| "#{kv_pair[0]}=#{kv_pair[1]}" }.join('&')
170
- # # get_vars = '' if get_vars == '?'
171
-
172
-
173
- # get_vars = '?' + params.to_a.sort.collect { |kv_pair|
174
- # if kv_pair[1].class == Array
175
- # puts "ARRAY"
176
- # kv_pair[1].each_with_index do |v, indx|
177
- # "#{kv_pair[0]}[#{indx}]=#{v}"
178
- # end
179
- # else
180
- # "#{kv_pair[0]}=#{kv_pair[1]}"
181
- # end
182
- # }.join('&')
183
- # get_vars = '' if get_vars == '?'
184
-
185
-
186
- # # puts "############################"
187
- # # puts "params: #{params}"
188
- # # puts '------------'
189
- # # puts "get_vars: #{get_vars}"
190
- # # puts "############################"
191
-
192
- # method_request = method.to_s.upcase
193
- # url = THE_CITY_ADMIN_PATH + path + get_vars
194
- # current_time = Time.now.to_i.to_s
195
- # string_to_sign = current_time.to_s + method_request + url
196
- # unencoded_hmac = OpenSSL::HMAC.digest('sha256', TheCity::AdminApi::API_KEY, string_to_sign)
197
- # unescaped_hmac = Base64.encode64(unencoded_hmac).chomp
198
- # hmac_signature = CGI.escape(unescaped_hmac)
199
-
200
- # headers = {'X-City-Sig' => hmac_signature,
201
- # 'X-City-User-Token' => TheCity::AdminApi::API_TOKEN,
202
- # 'X-City-Time' => current_time,
203
- # 'Accept' => 'application/vnd.thecity.admin.v1+json'}
204
-
205
-
206
- # # This is causing issues.... not sure if it is needed (docs might be lieing)
207
- # # if [:post, :put].include?(method)
208
- # # headers['Content-Type'] = 'application/json'
209
- # # headers['Content-Length'] = params.to_json.length
210
- # # end
211
-
212
- # headers
213
- # end
214
-
215
59
  end
@@ -1,6 +1,6 @@
1
1
  module CityKeys
2
2
 
3
- KEY = '66c59e2ee24553e7237259e30b4c17365681b95c'
4
- TOKEN = 'a9ae4af3c3e80102'
3
+ KEY = 'cf2903151e3213e66fd8080c7d8b65b1d6ccdd31'
4
+ TOKEN = '5c88b32edda7653c'
5
5
 
6
6
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  PROJECT_GEM = 'the-city-admin'
3
- PROJECT_GEM_VERSION = '0.1.1'
3
+ PROJECT_GEM_VERSION = '0.1.2'
4
4
 
5
5
  s.name = PROJECT_GEM
6
6
  s.version = PROJECT_GEM_VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the-city-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000 Z
12
+ date: 2012-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus