nds_api 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4336a2664e431cb4dc5ae26fba7a53175c36c13f9f00517cc7d7941ccb553613
4
- data.tar.gz: fba0168eae9939f7e921f0d2d42f25fc11fb4d81d511af0174afdf5b76919bb9
3
+ metadata.gz: 3ff25f4aa5ac9c5d7a6d6fecdd328f3cc1afcbf796298ac39fd1261428da1a2b
4
+ data.tar.gz: 29f356e9819fb9ffe7f76bc2eb2c92b6090580fb2e9a464e44c7cade4f5c9da6
5
5
  SHA512:
6
- metadata.gz: 2acbe60167c1e1ff434f46cb3f90bfdb8055af22be44731967c64b57e4b34f3ff2943857d2507bc147752139b402a1ca0c97348a9023669ea96cbdd77897fc3d
7
- data.tar.gz: 9244b5ddff0a135f29f46986f005d375c5ce1c33cfbcf9d959dc93e2213398c638cae4ebb877b4f27c6f04b792a4abbe958f60cebc7bd782992b5767e8289a1d
6
+ metadata.gz: c911221508e892aa31f3b8888525b27432a7bf9e0a1d6dc530c011087c15da567e29e82de074b0cfd3b9540bf68b80950dda4ef3a8ce64e4ba77222e134c934a
7
+ data.tar.gz: a152a13255b8e1b442f6e738d60298af0b967683bef7142700090ed0e8bcd1c3f9f755bc6e87551c7b7878e7013cbd7e3925885a6593b45dc2efe0de1599bb0a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nds_api (0.1.0)
4
+ nds_api (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -88,9 +88,10 @@ nds.positions_by_work_email(email)
88
88
  ##### PROVIDERS
89
89
 
90
90
  ```ruby
91
+ nds.search_providers(search_params)
91
92
  nds.update_provider(data)
92
93
 
93
- nds.providers()
94
+ nds.providers()
94
95
  nds.provider_by_uid(uid)
95
96
  nds.provider_by_id(id)
96
97
  nds.providers_by_center_name(center_name)
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+ task default: :spec
@@ -1,78 +1,46 @@
1
1
  require "nds_api/http"
2
+ require "nds_api/method"
2
3
  require "nds_api/url"
4
+ require "nds_api/utils"
3
5
  require "nds_api/version"
4
6
 
5
7
  module NdsApi
6
8
  class Client
7
-
8
9
  # Create a new client instance
9
10
  #
10
11
  # @param [Hash] options
11
12
  # @option options [String] :user NDS User
12
13
  # @option options [String] :password NDS Password
13
14
  #
14
- # @return [NdsApi::Client] a new client instance
15
-
16
-
17
- # NdsApi::Client.new({user: 'exygy', password: 'SnowflakeFrog?'}).providers
15
+ # @return [NdsApi::Client] new client instance
18
16
 
19
17
  def initialize(options = {})
20
18
  @options = options.dup
21
19
  @http = NdsApi::Http.new(options)
22
- @url = NdsApi::Url
20
+ @url = NdsApi::Url.new(options)
23
21
  end
24
22
 
25
23
  def method_missing(method, *args, &block)
26
- @method = method
27
- if is_create? or is_update?
28
- @args = args
29
- @http.post(@url.send(url), data) if is_create?
30
- @http.put(@url.send(url), data) if is_update?
31
- else
32
- @http.get(@url.send(method, *args, &block))
33
- end
24
+ @method = NdsApi::Method.new(method)
25
+ @args = *args
26
+ response = http_action(method, *args, &block)
27
+ NdsApi::Utils.hash_keys_str_to_sym(JSON.parse(response.body))
34
28
  end
35
29
 
36
30
  private
37
31
 
38
- def data
39
- @args[:data]
40
- end
41
-
42
- def method_split
43
- @method_split ||= method.split('_')
44
- end
45
-
46
- def is_create?
47
- method.include? 'create'
48
- end
49
-
50
- def is_update?
51
- method.include? 'update'
52
- end
53
-
54
- def method
55
- @method_str ||= @method.to_s
32
+ def http_action(method, *args, &block)
33
+ if @method.is_create? or @method.is_search?
34
+ @http.post(@url.send(@method.action), data)
35
+ elsif @method.is_update?
36
+ @http.put(@url.send(@method.action), data)
37
+ else
38
+ @http.get(@url.send(method, *args))
39
+ end
56
40
  end
57
41
 
58
- def url
59
- method_split ||= @method.split('_')
60
- action = method_split[0]
61
- object_type =
62
- case method_split[1]
63
- when 'child'
64
- 'children'
65
- when 'client'
66
- 'clients'
67
- when 'referral'
68
- 'referrals'
69
- when 'person'
70
- 'persons'
71
- when 'provider'
72
- 'providers'
73
- end
74
- "#{action}_#{object_type}"
42
+ def data
43
+ @args.include?(:data) ? @args[:data] : @args.first
75
44
  end
76
-
77
45
  end
78
46
  end
@@ -33,9 +33,9 @@ module NdsApi
33
33
  'Content-Type' => 'application/json'
34
34
  )
35
35
  req.basic_auth api_user, api_password
36
- req.use_ssl = true
37
- req.form_data(data)
38
- Net::HTTP.new(url.host, url.port).start{ |http| http.request(req) }
36
+ # req.use_ssl = true
37
+ req.body = data.to_json
38
+ Net::HTTP.new(url.host, url.port).request(req)
39
39
  rescue => e
40
40
  puts "failed #{e}"
41
41
  return e
@@ -0,0 +1,50 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'open-uri'
4
+ require 'uri'
5
+
6
+ module NdsApi
7
+ class Method
8
+ def initialize(method = '')
9
+ @method = method.to_s
10
+ end
11
+
12
+ def is_create?
13
+ @method.include? 'create'
14
+ end
15
+
16
+ def is_update?
17
+ @method.include? 'update'
18
+ end
19
+
20
+ def is_search?
21
+ @method.include? 'search'
22
+ end
23
+
24
+ def action
25
+ action = method_split[0]
26
+ object_type =
27
+ case method_split[1]
28
+ when 'child'
29
+ 'children'
30
+ when 'client'
31
+ 'clients'
32
+ when 'referral'
33
+ 'referrals'
34
+ when 'person'
35
+ 'persons'
36
+ when 'provider'
37
+ 'providers'
38
+ when 'providers'
39
+ 'providers'
40
+ end
41
+ "#{action}_#{object_type}"
42
+ end
43
+
44
+ private
45
+
46
+ def method_split
47
+ @method_split ||= @method.split('_')
48
+ end
49
+ end
50
+ end
@@ -1,141 +1,153 @@
1
1
  module NdsApi
2
- module Url
3
- class << self
4
- ##### CLIENTS #####
2
+ class Url
3
+ def initialize(options = { dev: false })
4
+ @prod = !options[:dev]
5
+ end
5
6
 
6
- def clients
7
- "#{base_url}/clients"
8
- end
7
+ ##### CLIENTS #####
9
8
 
10
- def client_by_email(email)
11
- "#{client_search}/findByEmail?email=#{email}"
12
- end
9
+ def clients
10
+ "#{base_url}/clients"
11
+ end
13
12
 
14
- def client_by_phone(phone)
15
- "#{client_search}/findByPhone?phone=#{phone}"
16
- end
13
+ def client_by_email(email)
14
+ "#{client_search}/findByEmail?email=#{email}"
15
+ end
17
16
 
18
- def client_by_first_name_and_last_name(first_name, last_name)
19
- "#{client_search}/findByName?lastName=#{last_name}&firstName=#{first_name}"
20
- end
17
+ def client_by_phone(phone)
18
+ "#{client_search}/findByPhone?phone=#{phone}"
19
+ end
21
20
 
22
- def client_by_id(id)
23
- "#{clients}/#{id}"
24
- end
21
+ def client_by_first_name_and_last_name(first_name, last_name)
22
+ "#{client_search}/findByName?lastName=#{last_name}&firstName=#{first_name}"
23
+ end
25
24
 
26
- ##### CHILDREN #####
25
+ def client_by_id(id)
26
+ "#{clients}/#{id}"
27
+ end
27
28
 
28
- def children
29
- "#{base_url}/children"
30
- end
29
+ ##### CHILDREN #####
31
30
 
32
- def child_by_uid(uid)
33
- "#{children}/#{uid}"
34
- end
31
+ def children
32
+ "#{base_url}/children"
33
+ end
35
34
 
36
- def children_by_client_id(client_id)
37
- "#{base_url}/clients/#{client_id}/children"
38
- end
35
+ def child_by_uid(uid)
36
+ "#{children}/#{uid}"
37
+ end
39
38
 
40
- ##### COMMUNITIES #####
39
+ def children_by_client_id(client_id)
40
+ "#{base_url}/clients/#{client_id}/children"
41
+ end
41
42
 
42
- def communities
43
- "#{base_url}/communities?sort=lastModifiedTime,DESC"
44
- end
43
+ ##### COMMUNITIES #####
45
44
 
46
- ##### PERSON #####
45
+ def communities
46
+ "#{base_url}/communities?sort=lastModifiedTime,DESC"
47
+ end
47
48
 
48
- def persons
49
- "#{base_url}/persons"
50
- end
49
+ ##### PERSON #####
51
50
 
52
- def person_by_id(id)
53
- "#{persons}/#{id}"
54
- end
51
+ def persons
52
+ "#{base_url}/persons"
53
+ end
55
54
 
56
- #### POSITIONS #####
55
+ def person_by_id(id)
56
+ "#{persons}/#{id}"
57
+ end
57
58
 
58
- def positions_by_work_email(email)
59
- "#{base_url}/positions/search/findByWorkEmail?workEmail=#{email}"
60
- end
59
+ #### POSITIONS #####
61
60
 
62
- ##### PROVIDERS #####
61
+ def positions_by_work_email(email)
62
+ "#{base_url}/positions/search/findByWorkEmail?workEmail=#{email}"
63
+ end
63
64
 
64
- def providers
65
- "#{base_url}/providers"
66
- end
65
+ ##### PROVIDERS #####
67
66
 
68
- def provider_by_uid(uid)
69
- "#{base_url}/providers/#{uid}"
70
- end
67
+ def search_providers
68
+ stg_search = 'http://staging-nds-api-app.emrcsv38cq.us-east-1.elasticbeanstalk.com/providers/search/findByCriteriaObject'
69
+ prod_search = 'http://www.google.com'
71
70
 
72
- def provider_by_id(id)
73
- "#{base_url}/providers/search/findByProviderId?providerId=#{id}"
74
- end
71
+ puts @prod ? prod_search : stg_search
75
72
 
76
- def providers_by_center_name(center_name)
77
- "#{provider_search}/findByCenterName?centerName=#{center_name}"
78
- end
73
+ @prod ? prod_search : stg_search
74
+ end
79
75
 
80
- def providers_by_email(email)
81
- "#{provider_search}/findByEmail?email=#{email}"
82
- end
76
+ def providers
77
+ "#{base_url}/providers"
78
+ end
83
79
 
84
- def provider_schedule(uid)
85
- "#{providers}/#{uid}/schedule"
86
- end
80
+ def provider_by_uid(uid)
81
+ "#{base_url}/providers/#{uid}"
82
+ end
87
83
 
88
- def provider_rates(uid)
89
- "#{providers}/#{uid}/rates"
90
- end
84
+ def provider_by_id(id)
85
+ "#{base_url}/providers/search/findByProviderId?providerId=#{id}"
86
+ end
91
87
 
92
- def provider_enrollments(uid)
93
- "#{providers}/#{uid}/enrollments"
94
- end
88
+ def providers_by_center_name(center_name)
89
+ "#{provider_search}/findByCenterName?centerName=#{center_name}"
90
+ end
95
91
 
96
- ##### REFERRALS #####
92
+ def providers_by_email(email)
93
+ "#{provider_search}/findByEmail?email=#{email}"
94
+ end
97
95
 
98
- def referrals
99
- "#{base_url}/referrals"
100
- end
96
+ def provider_schedule(uid)
97
+ "#{providers}/#{uid}/schedule"
98
+ end
101
99
 
102
- def referral_by_id(id)
103
- "#{referrals}/#{id}"
104
- end
100
+ def provider_rates(uid)
101
+ "#{providers}/#{uid}/rates"
102
+ end
105
103
 
106
- def referral_by_client_id(id)
107
- "#{clients}/#{id}/referrals"
108
- end
104
+ def provider_enrollments(uid)
105
+ "#{providers}/#{uid}/enrollments"
106
+ end
109
107
 
110
- def referrals_before_date(date)
111
- "#{referral_search}/findByDateBefore?date=#{date}"
112
- end
108
+ ##### REFERRALS #####
113
109
 
114
- def referrals_after_date(date)
115
- "#{referral_search}/findByDateAfter?date=#{date}"
116
- end
110
+ def referrals
111
+ "#{base_url}/referrals"
112
+ end
117
113
 
118
- def referrals_in_date_range(start_date, end_date)
119
- "#{referral_search}/findByDateBetween?startDate=#{start_date}&endDate=#{end_date}"
120
- end
114
+ def referral_by_id(id)
115
+ "#{referrals}/#{id}"
116
+ end
121
117
 
122
- private
118
+ def referral_by_client_id(id)
119
+ "#{clients}/#{id}/referrals"
120
+ end
123
121
 
124
- def client_search
125
- "#{clients}/search"
126
- end
122
+ def referrals_before_date(date)
123
+ "#{referral_search}/findByDateBefore?date=#{date}"
124
+ end
127
125
 
128
- def provider_search
129
- "#{providers}/search"
130
- end
126
+ def referrals_after_date(date)
127
+ "#{referral_search}/findByDateAfter?date=#{date}"
128
+ end
131
129
 
132
- def referral_search
133
- "#{referrals}/search"
134
- end
130
+ def referrals_in_date_range(start_date, end_date)
131
+ "#{referral_search}/findByDateBetween?startDate=#{start_date}&endDate=#{end_date}"
132
+ end
133
+
134
+ private
135
+
136
+ def client_search
137
+ "#{clients}/search"
138
+ end
139
+
140
+ def provider_search
141
+ "#{providers}/search"
142
+ end
143
+
144
+ def referral_search
145
+ "#{referrals}/search"
146
+ end
135
147
 
136
- def base_url
137
- 'https://uatup.naccrraware.net/nds-api'
138
- end
148
+ def base_url
149
+ sub_domain = @prod ? 'uatup' : 'developer.staging'
150
+ "https://#{sub_domain}.naccrraware.net/nds-api"
139
151
  end
140
152
  end
141
153
  end
@@ -0,0 +1,11 @@
1
+ module NdsApi
2
+ module Utils
3
+ class << self
4
+
5
+ def hash_keys_str_to_sym(hash)
6
+ hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module NdsApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Pierre Hunault"]
10
10
  spec.email = ["pierre@exygy.com"]
11
11
 
12
- spec.summary = %q{Connect to NDS API and retrieve records.}
13
- spec.description = %q{Connect to NDS API and retrieve records.}
12
+ spec.summary = %q{NDS API is a Rubygem for easy interface with the NDS API. https://developer.uatup.naccrraware.net/}
13
+ spec.description = %q{NDS API is a Rubygem for easy interface with the NDS API. NDS is the National Data System for Child Care. NDS is a variety of applications and services that facilitate the work of Child Care R&Rs. This Ruby code is an interface to the new NDS API. This code is built and maintained by Exygy, in San Francisco. NDS is built by Child Care Aware of America. For any questions about using this code, please contact hello@exygy.com. For more information about NDS please see https://usa.childcareaware.org/members-providers/data-services/}
14
14
  spec.homepage = "http://exygy.com"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nds_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Hunault
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-26 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,12 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '12.0'
41
- description: Connect to NDS API and retrieve records.
41
+ description: NDS API is a Rubygem for easy interface with the NDS API. NDS is the
42
+ National Data System for Child Care. NDS is a variety of applications and services
43
+ that facilitate the work of Child Care R&Rs. This Ruby code is an interface to the
44
+ new NDS API. This code is built and maintained by Exygy, in San Francisco. NDS is
45
+ built by Child Care Aware of America. For any questions about using this code, please
46
+ contact hello@exygy.com. For more information about NDS please see https://usa.childcareaware.org/members-providers/data-services/
42
47
  email:
43
48
  - pierre@exygy.com
44
49
  executables: []
@@ -55,7 +60,9 @@ files:
55
60
  - bin/setup
56
61
  - lib/nds_api.rb
57
62
  - lib/nds_api/http.rb
63
+ - lib/nds_api/method.rb
58
64
  - lib/nds_api/url.rb
65
+ - lib/nds_api/utils.rb
59
66
  - lib/nds_api/version.rb
60
67
  - nds_api.gemspec
61
68
  homepage: http://exygy.com
@@ -81,5 +88,5 @@ rubyforge_project:
81
88
  rubygems_version: 2.7.6
82
89
  signing_key:
83
90
  specification_version: 4
84
- summary: Connect to NDS API and retrieve records.
91
+ summary: NDS API is a Rubygem for easy interface with the NDS API. https://developer.uatup.naccrraware.net/
85
92
  test_files: []