the-city-admin 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +9 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.yardoc/checksums +50 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +51 -0
- data/README +1 -0
- data/Rakefile +32 -0
- data/index.rb +123 -0
- data/lib/common.rb +163 -72
- data/lib/the_city_admin.rb +2 -2
- data/notes.txt +21 -0
- data/spec/api/address_list_spec.rb +0 -0
- data/spec/api/address_spec.rb +0 -0
- data/spec/api/group_address_list_spec.rb +93 -0
- data/spec/api/group_address_spec.rb +19 -0
- data/spec/api/group_checkin_list_spec.rb +93 -0
- data/spec/api/group_event_attendance_list_spec.rb +93 -0
- data/spec/api/group_export_spec.rb +19 -0
- data/spec/api/group_invitation_list_spec.rb +23 -0
- data/spec/api/group_invitation_spec.rb +19 -0
- data/spec/api/group_list_spec.rb +23 -0
- data/spec/api/group_role_list_spec.rb +23 -0
- data/spec/api/group_role_spec.rb +19 -0
- data/spec/api/group_spec.rb +19 -0
- data/spec/api/group_tag_list_spec.rb +23 -0
- data/spec/api/group_tag_spec.rb +19 -0
- data/spec/api/metric_list_spec.rb +22 -0
- data/spec/api/metric_measurement_list_spec.rb +23 -0
- data/spec/api/metric_measurement_spec.rb +19 -0
- data/spec/api/metric_spec.rb +19 -0
- data/spec/api/role_list_spec.rb +75 -0
- data/spec/api/role_spec.rb +19 -0
- data/spec/api/skill_list_spec.rb +76 -0
- data/spec/api/skilled_user_id_list_spec.rb +82 -0
- data/spec/api/skilled_user_list_spec.rb +82 -0
- data/spec/api/tag_group_list_spec.rb +72 -0
- data/spec/api/tag_list_spec.rb +77 -0
- data/spec/api/tag_spec.rb +19 -0
- data/spec/api/terminology_list_spec.rb +75 -0
- data/spec/api/terminology_spec.rb +19 -0
- data/spec/api/user_address_list_spec.rb +92 -0
- data/spec/api/user_address_spec.rb +19 -0
- data/spec/api/user_admin_privilege_list_spec.rb +94 -0
- data/spec/api/user_admin_privilege_spec.rb +19 -0
- data/spec/api/user_barcode_spec.rb +19 -0
- data/spec/api/user_family_list_spec.rb +91 -0
- data/spec/api/user_family_member_spec.rb +19 -0
- data/spec/api/user_invitation_list_spec.rb +91 -0
- data/spec/api/user_invitation_spec.rb +19 -0
- data/spec/api/user_list_spec.rb +76 -0
- data/spec/api/user_note_list_spec.rb +91 -0
- data/spec/api/user_note_spec.rb +19 -0
- data/spec/api/user_process_list_spec.rb +90 -0
- data/spec/api/user_process_spec.rb +19 -0
- data/spec/api/user_role_list_spec.rb +92 -0
- data/spec/api/user_role_spec.rb +18 -0
- data/spec/api/user_skill_list_spec.rb +91 -0
- data/spec/api/user_skill_spec.rb +19 -0
- data/spec/api/user_spec.rb +37 -0
- data/spec/api/web_hook_list_spec.rb +75 -0
- data/spec/api/web_hook_spec.rb +19 -0
- data/spec/factories/address.rb +21 -0
- data/spec/factories/address_list.rb +13 -0
- data/spec/factories/checkin.rb +35 -0
- data/spec/factories/checkin_list.rb +13 -0
- data/spec/factories/group.rb +30 -0
- data/spec/factories/group_address.rb +21 -0
- data/spec/factories/group_address_list.rb +13 -0
- data/spec/factories/group_checkin.rb +35 -0
- data/spec/factories/group_checkin_list.rb +13 -0
- data/spec/factories/group_event_attendance.rb +19 -0
- data/spec/factories/group_event_attendance_list.rb +13 -0
- data/spec/factories/group_export.rb +16 -0
- data/spec/factories/group_export_list.rb +13 -0
- data/spec/factories/group_role.rb +19 -0
- data/spec/factories/group_tag.rb +12 -0
- data/spec/factories/role.rb +22 -0
- data/spec/factories/role_list.rb +13 -0
- data/spec/factories/skill.rb +13 -0
- data/spec/factories/skill_list.rb +13 -0
- data/spec/factories/skilled_user_id_list.rb +13 -0
- data/spec/factories/skilled_user_list.rb +13 -0
- data/spec/factories/tag.rb +13 -0
- data/spec/factories/tag_group_list.rb +13 -0
- data/spec/factories/tag_list.rb +13 -0
- data/spec/factories/terminology.rb +10 -0
- data/spec/factories/terminology_list.rb +13 -0
- data/spec/factories/user.rb +51 -0
- data/spec/factories/user_address.rb +19 -0
- data/spec/factories/user_address_list.rb +13 -0
- data/spec/factories/user_admin_privilege.rb +11 -0
- data/spec/factories/user_admin_privilege_list.rb +13 -0
- data/spec/factories/user_barcode.rb +15 -0
- data/spec/factories/user_family_list.rb +13 -0
- data/spec/factories/user_family_member.rb +28 -0
- data/spec/factories/user_invitation.rb +16 -0
- data/spec/factories/user_invitation_list.rb +13 -0
- data/spec/factories/user_list.rb +13 -0
- data/spec/factories/user_note.rb +28 -0
- data/spec/factories/user_note_list.rb +13 -0
- data/spec/factories/user_process.rb +11 -0
- data/spec/factories/user_process_list.rb +13 -0
- data/spec/factories/user_role.rb +17 -0
- data/spec/factories/user_role_list.rb +13 -0
- data/spec/factories/user_skill.rb +10 -0
- data/spec/factories/user_skill_list.rb +13 -0
- data/spec/factories/web_hook.rb +12 -0
- data/spec/factories/web_hook_list.rb +13 -0
- data/spec/functional/the_city_admin_spec.rb +20 -0
- data/spec/readers/user_reader_spec.rb +7 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/writers/skill_writer_spec.rb +0 -0
- data/spec/writers/tag_writer_spec.rb +80 -0
- data/spec/writers/user_writer_spec.rb +80 -0
- data/status.txt +187 -0
- data/test_scripts/addresses.rb +36 -0
- data/test_scripts/barcodes_checkins.rb +45 -0
- data/test_scripts/city_keys.rb +6 -0
- data/test_scripts/familes.rb +83 -0
- data/test_scripts/groups.rb +124 -0
- data/test_scripts/metrics.rb +72 -0
- data/test_scripts/roles.rb +94 -0
- data/test_scripts/skills.rb +55 -0
- data/test_scripts/tags.rb +71 -0
- data/test_scripts/terminology.rb +62 -0
- data/test_scripts/users.rb +325 -0
- data/test_scripts/webhooks.rb +57 -0
- data/thecity_admin_api.gemspec +39 -0
- data/thecity_headers.rb +27 -0
- metadata +238 -3
data/.autotest
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Autotest.add_hook(:initialize) {|at|
|
2
|
+
at.add_exception %r{^\.git} # ignore Version Control System
|
3
|
+
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
|
4
|
+
# at.clear_mappings # take out the default (test/test*rb)
|
5
|
+
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
|
6
|
+
Dir['spec/**/*.rb']
|
7
|
+
}
|
8
|
+
nil
|
9
|
+
}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm ruby-1.9.2-p290@admin-api
|
data/.yardoc/checksums
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
lib/api/user.rb 5dade14583140e58467fe81ec6d9dcd8cb7ce771
|
2
|
+
lib/api/group.rb 688af7befcf3625562a4aef1dc504acb3ceab9a5
|
3
|
+
lib/api/user_list.rb f44fbcb17b7bd5af0c8badc962cc002eb1515b1a
|
4
|
+
lib/api/user_note.rb 7eab928ca4fd289d173da2328d1287bcc8e0ec86
|
5
|
+
lib/api/user_role.rb 6c94d6554127bd5ba7dd8fa5a1d8050e69a79762
|
6
|
+
lib/api/group_tag.rb 9cf763bb34b213c693607b29da52ea1f3ea8ab43
|
7
|
+
lib/api/api_object.rb f9bd763bcac5924f26aabcaf031db815327781e3
|
8
|
+
lib/api/group_role.rb 00f19d0474379a62eea84497de5061d66a7865a6
|
9
|
+
lib/api/group_list.rb 0e735c638cf75d927a992d45d3a9bd8d2c6a847c
|
10
|
+
lib/api/user_skill.rb 8ea23049d38ea56a58e931a1f25c02115d176522
|
11
|
+
lib/api/user_process.rb 2248b5aac1a9777669d0884296ae00fbed3a0cbe
|
12
|
+
lib/savers/api_saver.rb 84647040fa91876aede6c7fd96852d90673cbc0e
|
13
|
+
lib/api/user_address.rb 0e0aee03c01396688a613dd25d0e9bfe2ab62568
|
14
|
+
lib/api/group_address.rb 0e0aee03c01396688a613dd25d0e9bfe2ab62568
|
15
|
+
lib/savers/user_saver.rb bfeb601f57cbe388c36a7fe6fb11211a1fb2d929
|
16
|
+
lib/api/group_tag_list.rb 3176b69b88ab4d57ab0055a96a79d6e4f652220d
|
17
|
+
lib/savers/group_saver.rb 02f37545a177d9a7e750672d271e246bb323d028
|
18
|
+
lib/loaders/api_loader.rb 7610bcecd9a4ef7d26cb798e7020b42fa678a47a
|
19
|
+
lib/api/user_role_list.rb 6a145e707f6983de15bed5e4f68d3ef4b4f3a441
|
20
|
+
lib/api/user_note_list.rb 68b9a7891cac8c1b65bdddfa4f34b63fe00c73a4
|
21
|
+
lib/api/user_skill_list.rb 3dcae8a035930c13dc94c9486fcd954877babd69
|
22
|
+
lib/loaders/user_loader.rb 81063767128f7531b09b184c36bcbeae2ae4fdc0
|
23
|
+
lib/api/group_role_list.rb ebfc563a4a515598eaa7cfaf100b05b8d6db5125
|
24
|
+
lib/api/user_invitation.rb 2795c3fb3149560e3dcd69dba6a05034150fe76b
|
25
|
+
lib/api/user_family_list.rb f01ea5f60815860074b0e0cbcbe6fc745f346326
|
26
|
+
lib/api/group_invitation.rb 6185ab5951831992988996fb00953b956df5d560
|
27
|
+
lib/loaders/group_loader.rb 4c12f649c547633ad94616a4ae5cc8c1de6fe13c
|
28
|
+
lib/cachers/cache_adapter.rb b05d6e2d541c09245e515ef55228cbcdcbfce049
|
29
|
+
lib/api/user_address_list.rb 2d39275605b855509918fdb3320c93ae618dc96a
|
30
|
+
lib/api/user_process_list.rb e2f4fb3a792253a7a0857b07af90155d84676d55
|
31
|
+
lib/api/group_address_list.rb d3bceba9f2f0ad1c576d9dc43e02064f5eadc16f
|
32
|
+
lib/api/user_family_member.rb e45c848b782a3267b90001e530115d006cbb543c
|
33
|
+
lib/loaders/user_list_loader.rb 82ae7ec17a0dfaefb5d475a09c5aa28cb793eefc
|
34
|
+
lib/api/user_invitation_list.rb 0f5de9a0c65ec3cdb712a1b822d4fa6c7bdff142
|
35
|
+
lib/api/user_admin_privilege.rb c44d44c7f5aecbc397b83b6c7daba310cee08b87
|
36
|
+
lib/api/group_invitation_list.rb c64c56679a79b5bf2ce8d17b811a18d4617c5cbd
|
37
|
+
lib/loaders/group_list_loader.rb 1b1d7d5eda23bee37bfe2d4204d1399e11ffda7a
|
38
|
+
lib/loaders/user_role_list_loader.rb eaf1e78c3947f7eb80d0dde2e5237025f610ad2f
|
39
|
+
lib/loaders/user_note_list_loader.rb 59e861cbaf5536e0851f4be181a629acd2621937
|
40
|
+
lib/loaders/group_tag_list_loader.rb 2b17f2af70ed7a1e9e45657f45f2e5fd75657404
|
41
|
+
lib/api/user_admin_privilege_list.rb 7c954ccdd8b9e4d270ded17c253d23b4fd7a9f28
|
42
|
+
lib/loaders/user_skill_list_loader.rb db64c1cffac257fbde2ff6b9a236a7170e58cba1
|
43
|
+
lib/loaders/group_role_list_loader.rb f49af8592fc34fc59c155bddbb7f188c3f956979
|
44
|
+
lib/loaders/user_family_list_loader.rb dc5336a91f6f7b061f362d682edeebacb0bcac76
|
45
|
+
lib/loaders/user_process_list_loader.rb 656704758d8369d6391865172a56afa40d3ddc06
|
46
|
+
lib/loaders/user_address_list_loader.rb 43d91cf3866e6cfad97339325e36065c5db6cf52
|
47
|
+
lib/loaders/group_address_list_loader.rb 1b6e628a464d345bdb8beb1cbc5570d3104eeaf6
|
48
|
+
lib/loaders/user_invitation_list_loader.rb dfa2590f8d1a122a34d147a38be9c6bf21927c57
|
49
|
+
lib/loaders/group_invitation_list_loader.rb 81c117073f3f950f8aca7b05ba6b596e6bc6d681
|
50
|
+
lib/loaders/user_admin_privilege_list_loader.rb 314945a85d2c789060066f9629596f66915d892b
|
Binary file
|
Binary file
|
data/.yardoc/proxy_types
ADDED
Binary file
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.8.1)
|
5
|
+
activesupport (3.2.6)
|
6
|
+
i18n (~> 0.6)
|
7
|
+
multi_json (~> 1.0)
|
8
|
+
archive-tar-minitar (0.5.2)
|
9
|
+
autotest (4.4.6)
|
10
|
+
ZenTest (>= 4.4.1)
|
11
|
+
columnize (0.3.6)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
factory_girl (3.5.0)
|
14
|
+
activesupport (>= 3.0.0)
|
15
|
+
i18n (0.6.0)
|
16
|
+
json (1.7.3)
|
17
|
+
linecache19 (0.5.12)
|
18
|
+
ruby_core_source (>= 0.1.4)
|
19
|
+
mime-types (1.18)
|
20
|
+
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)
|
29
|
+
ruby-debug-base19 (0.11.25)
|
30
|
+
columnize (>= 0.3.1)
|
31
|
+
linecache19 (>= 0.5.11)
|
32
|
+
ruby_core_source (>= 0.1.4)
|
33
|
+
ruby-debug19 (0.11.6)
|
34
|
+
columnize (>= 0.3.1)
|
35
|
+
linecache19 (>= 0.5.11)
|
36
|
+
ruby-debug-base19 (>= 0.11.19)
|
37
|
+
ruby_core_source (0.1.5)
|
38
|
+
archive-tar-minitar (>= 0.5.2)
|
39
|
+
typhoeus (0.3.3)
|
40
|
+
mime-types
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
autotest
|
47
|
+
factory_girl
|
48
|
+
json
|
49
|
+
rspec
|
50
|
+
ruby-debug19
|
51
|
+
typhoeus
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This Ruby project is an API wrapper for TheCity Admin API (OnTheCity.org)
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
|
3
|
+
|
4
|
+
desc 'Default: run specs.'
|
5
|
+
task :default => :spec
|
6
|
+
task :test => :spec
|
7
|
+
|
8
|
+
desc "Run specs"
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
11
|
+
# Put spec opts in a file named .rspec in root
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
desc "Generate code coverage"
|
16
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
17
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
18
|
+
t.rcov = true
|
19
|
+
t.rcov_opts = ['--exclude', 'spec']
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
namespace :docs do
|
25
|
+
|
26
|
+
desc 'Build the docs for The City Admin API.'
|
27
|
+
task :build do
|
28
|
+
system('rm -rf doc')
|
29
|
+
system('yardoc --no-private --protected lib/**/*.rb')
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/index.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# *******************************************
|
2
|
+
# This is a demo file to show usage.
|
3
|
+
#
|
4
|
+
# @package TheCity::Admin
|
5
|
+
# @authors Robbie Lieb <robbie@onthecity.org>, Wes Hays <wes@onthecity.org>
|
6
|
+
# *******************************************
|
7
|
+
|
8
|
+
require 'ruby-debug'
|
9
|
+
require File.dirname(__FILE__) + '/lib/the_city_admin.rb'
|
10
|
+
|
11
|
+
# staging
|
12
|
+
# key = 'bc6b57204b0ee4818bb4b3befd0f3292e93a2d0a'
|
13
|
+
# token = '7cfed59b037125d3'
|
14
|
+
|
15
|
+
# Local
|
16
|
+
key = '66c59e2ee24553e7237259e30b4c17365681b95c'
|
17
|
+
token = 'a9ae4af3c3e80102'
|
18
|
+
|
19
|
+
|
20
|
+
TheCity::AdminApi.connect(key, token)
|
21
|
+
|
22
|
+
###### USERS / GROUPS #######
|
23
|
+
|
24
|
+
puts "-----------------------------"
|
25
|
+
|
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
|
51
|
+
|
52
|
+
|
53
|
+
# puts "-----------------------------"
|
54
|
+
|
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
|
64
|
+
|
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
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
###### USERS #######
|
77
|
+
|
78
|
+
# user = the_city.users[0]
|
79
|
+
# puts user.full_name
|
80
|
+
|
81
|
+
|
82
|
+
# user2 = TheCity::User.load_user_by_id(1068169470) #(564114313)
|
83
|
+
# puts user2.full_name
|
84
|
+
|
85
|
+
# user = the_city.users[1]
|
86
|
+
# puts user.full_name
|
87
|
+
|
88
|
+
# This is currenly returning a 404 if no family members are found
|
89
|
+
# puts user.family[0].name
|
90
|
+
|
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
|
+
|
99
|
+
|
100
|
+
###### GROUPS #######
|
101
|
+
|
102
|
+
# group = the_city.groups[0]
|
103
|
+
# puts group.name
|
104
|
+
# puts group.id
|
105
|
+
|
106
|
+
# Fails with 500 error
|
107
|
+
# puts group.addresses[0].location_type
|
108
|
+
|
109
|
+
# puts group.roles[0].user_name
|
110
|
+
# puts group.tags[0].name
|
111
|
+
|
112
|
+
# puts group.invitations[0].source
|
113
|
+
|
114
|
+
# metric = the_city.metrics[0]
|
115
|
+
|
116
|
+
# puts metric.name
|
117
|
+
# metric.measurements.total_entries.times do |i|
|
118
|
+
# puts "#{metric.measurements[i].created_at}: #{metric.measurements[i].value}"
|
119
|
+
# end
|
120
|
+
# new_measurement = TheCity::MetricMeasurement.new(:id => metric.id, :value => 999)
|
121
|
+
# new_measurement.save
|
122
|
+
|
123
|
+
|
data/lib/common.rb
CHANGED
@@ -1,31 +1,38 @@
|
|
1
1
|
module TheCity
|
2
2
|
require 'cgi'
|
3
3
|
|
4
|
-
def self.admin_request(method, path, params = {})
|
5
|
-
# data_params = params.inject({}) {|h, (k,v)| h.update({k => v.nil? ? v : v.to_s})}
|
6
|
-
# flattened_params = self._flatten_params(data_params)
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
# puts "############################"
|
11
|
-
# puts "flattened_params: #{flattened_params}"
|
12
|
-
# puts "############################"
|
13
|
-
|
14
|
-
headers = self._build_admin_headers(method, path, flattened_params)
|
5
|
+
def self.admin_request(method, path, params = {})
|
6
|
+
headers = self._build_admin_headers(method, path, params)
|
15
7
|
url = THE_CITY_ADMIN_PATH+path
|
16
8
|
|
17
|
-
|
18
|
-
|
9
|
+
data_params = params.inject({}) {|h, (k,v)| h.update({k => v.nil? ? v : CGI.escape(v.to_s)})}
|
10
|
+
|
11
|
+
response =
|
12
|
+
case method
|
19
13
|
when :post
|
20
|
-
Typhoeus::Request.post(url, {:headers => headers, :params =>
|
21
|
-
when :get
|
22
|
-
Typhoeus::Request.get(url, {:headers => headers, :params =>
|
23
|
-
when :put
|
24
|
-
Typhoeus::Request.put(url, {:headers => headers, :params =>
|
25
|
-
when :delete
|
26
|
-
Typhoeus::Request.delete(url, {:headers => headers, :params =>
|
14
|
+
Typhoeus::Request.post(url, {:headers => headers, :params => self._flatten_params(data_params)})
|
15
|
+
when :get
|
16
|
+
Typhoeus::Request.get(url, {:headers => headers, :params => self._flatten_params(data_params)})
|
17
|
+
when :put
|
18
|
+
Typhoeus::Request.put(url, {:headers => headers, :params => self._flatten_params(data_params)})
|
19
|
+
when :delete
|
20
|
+
Typhoeus::Request.delete(url, {:headers => headers, :params => self._flatten_params(data_params)})
|
27
21
|
end
|
28
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
|
+
|
35
|
+
|
29
36
|
unless response.success?
|
30
37
|
if response.curl_error_message != 'No error'
|
31
38
|
raise TheCityExceptions::UnableToConnectToTheCity.new(response.curl_error_message)
|
@@ -38,66 +45,28 @@ module TheCity
|
|
38
45
|
raise TheCityExceptions::TheCityResponseError.new(error_messages)
|
39
46
|
end
|
40
47
|
end
|
41
|
-
end
|
42
|
-
|
48
|
+
end
|
49
|
+
|
43
50
|
response
|
44
51
|
end
|
45
52
|
|
46
53
|
|
47
|
-
def self._flatten_params(params
|
48
|
-
retval =
|
49
|
-
|
50
|
-
if
|
51
|
-
|
52
|
-
else
|
53
|
-
|
54
|
-
retval << self._flatten_params(value, "#{prefix.to_s}[#{indx}]")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
elsif params.instance_of?(Hash)
|
58
|
-
params.each do |key, value|
|
59
|
-
retval << self._flatten_params(value, prefix.empty? ? key.to_s : "#{prefix}[#{key.to_s}]")
|
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
|
60
61
|
end
|
61
|
-
else # assume string
|
62
|
-
retval << "#{prefix}=#{params}"
|
63
62
|
end
|
64
|
-
|
65
|
-
if prefix.empty?
|
66
|
-
hvals = {}
|
67
|
-
retval.flatten.sort.each { |v| hvals[v.split('=')[0]] = v.split('=')[1] }
|
68
|
-
hvals
|
69
|
-
else
|
70
|
-
retval.flatten.sort
|
71
|
-
end
|
72
|
-
#retval.flatten.sort
|
63
|
+
retval
|
73
64
|
end
|
74
65
|
|
75
66
|
|
76
|
-
|
77
|
-
|
78
|
-
# get_vars = '?' + params.to_a.sort.collect { |kv_pair| "#{kv_pair[0]}=#{kv_pair[1]}" }.join('&')
|
79
|
-
# get_vars = '' if get_vars == '?'
|
80
|
-
|
81
|
-
|
82
|
-
get_vars = '?' + params.to_a.sort.collect { |kv_pair|
|
83
|
-
if kv_pair[1].class == Array
|
84
|
-
puts "ARRAY"
|
85
|
-
kv_pair[1].each_with_index do |v, indx|
|
86
|
-
"#{kv_pair[0]}[#{indx}]=#{v}"
|
87
|
-
end
|
88
|
-
else
|
89
|
-
"#{kv_pair[0]}=#{kv_pair[1]}"
|
90
|
-
end
|
91
|
-
}.join('&')
|
67
|
+
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('&')
|
92
69
|
get_vars = '' if get_vars == '?'
|
93
|
-
|
94
|
-
|
95
|
-
# puts "############################"
|
96
|
-
# puts "params: #{params}"
|
97
|
-
# puts '------------'
|
98
|
-
# puts "get_vars: #{get_vars}"
|
99
|
-
# puts "############################"
|
100
|
-
|
101
70
|
method_request = method.to_s.upcase
|
102
71
|
url = THE_CITY_ADMIN_PATH + path + get_vars
|
103
72
|
current_time = Time.now.to_i.to_s
|
@@ -114,11 +83,133 @@ module TheCity
|
|
114
83
|
|
115
84
|
# This is causing issues.... not sure if it is needed (docs might be lieing)
|
116
85
|
# if [:post, :put].include?(method)
|
117
|
-
#
|
118
|
-
#
|
86
|
+
# headers['Content-Type'] = 'application/json'
|
87
|
+
# headers['Content-Length'] = params.to_json.length
|
119
88
|
# end
|
120
89
|
|
121
90
|
headers
|
122
|
-
end
|
91
|
+
end
|
92
|
+
|
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
|
123
214
|
|
124
215
|
end
|