regis 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTk1MjgwNDEwODYyOGZjNGJhZTkwOTBmNzNiNWRkNWQzYTA3NTZiMQ==
4
+ YzMxNTA1YmRmMzkwNGIxZmRkNzUzMTA3YTdiZTBhMGE4ZDdjZWYyNw==
5
5
  data.tar.gz: !binary |-
6
- Y2I4N2FjN2M1NzZhN2YxYTZmZGVjOGZkNDk1MGQyZDA2MjlmMzllMw==
6
+ NTBmZTAxYmE1ZmYxYmExNTdlYzkzZjVlMDY4NDgxNDI1MjY1ODlhZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTU1NGU1ODVlMTU0ZjZhMjU4MTkzOTVlYTE3OTg0MGQ3YWViNmQ3YmY1ZmJl
10
- ZjNmN2FlYzRjMWFhMTRjODA2ODg5MmUwMzllMWQ1ZmIxYzlkYWVkZGU4Y2Rk
11
- MGZiMTIxMGE0ZjUwZDUwYTIzNTMyN2U2MDdkMDIzNzhjOTQyNzI=
9
+ NDJiMTBhODY3ZDJjYzk4Y2QyZDFmZTZjZjFiNWNlOTJiOWJkYzYyODk0OWM0
10
+ MmZmZWVkZjQ1NDUxYWNjYjFlZTBkZjJiNjg5Y2FjYTUwZDU3OGNmYzZmMWEy
11
+ MzA5N2I0MzU4ZjlkZWJlZDQ4NGFmMTJlMzQ3OGE5MWRlZWZmYWE=
12
12
  data.tar.gz: !binary |-
13
- N2EwMjQyMzk5NmY2N2JiY2Y2ZWNlYmY2MjU1NTI1MmY0MTUzMDRjN2I0YmQ0
14
- ZWY5MmM3YmRjODdmY2ViZGE1NGQ3ODViZTBlMzM5YTUxZDcwNjczMzZkYjFj
15
- MTY5OWNlNjQ4YzU5MmExMTA4MzM0NzkyOTdiZjdmM2MwMTY3OTQ=
13
+ M2ZmMzk2OGJmYjU5ZjhjYzEzMTk0MjI3Njk4YzRjYWQyYmQzZmI5ZjBkMzRi
14
+ ZDg2Zjg2YTVjYzRhZGRmMmQ1MmMwZTVlYzE4OWFiYTI1N2VkMTA2ODVkNWJi
15
+ MDdiNzVmOWM0YTFmYmI4OGU4YzQ3ZTBjMzAzZDNiZDdlNGJmOWU=
data/.gitignore CHANGED
@@ -31,9 +31,10 @@ build/
31
31
 
32
32
  # for a library or gem, you might want to ignore these files since the code is
33
33
  # intended to run in multiple environments; otherwise, check them in:
34
- # Gemfile.lock
35
- # .ruby-version
36
- # .ruby-gemset
34
+ Gemfile.lock
35
+ .ruby-version
36
+ .ruby-gemset
37
37
 
38
38
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39
39
  .rvmrc
40
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in regis.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -16,11 +16,37 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install regis
18
18
 
19
- # Configuration
19
+ Responses are cached with Dalli which requires memcached
20
+
21
+ $ apt-get install memcached
22
+
23
+ ## Configuration
20
24
 
21
25
  Set config/regis_api.yml
22
- Set features/config/test_values.yml
26
+
27
+ ```
28
+ require 'regis'
29
+
30
+ $REGIS_API = YAML.load_file("config/regis_api.yml")
31
+
32
+ Regis.client.configure do |config|
33
+ config.url = $REGIS_API['url']
34
+ config.username = $REGIS_API['username']
35
+ config.password = $REGIS_API['password']
36
+ config.cache = Regis::Cache.new(Dalli::Client.new('localhost:11211', { :namespace => "regis", :compress => true, :expires_in => 3600 }))
37
+ end
38
+ ```
23
39
 
24
40
  ## Usage
25
41
 
26
- See features/step_definitions/api_steps
42
+ See features/step_definitions/api_steps
43
+
44
+ ## Caching
45
+
46
+ All responses are cached based on the request URL. So, all endpoints must include variables in the URL itself.
47
+
48
+ ## Testing
49
+
50
+ Set features/config/test_values.yml
51
+
52
+ $ cucumber
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :test
3
+
4
+ task :test => [:cucumber]
@@ -0,0 +1,10 @@
1
+ require 'regis'
2
+
3
+ $REGIS_API = YAML.load_file("config/regis_api.yml")
4
+
5
+ Regis.client.configure do |config|
6
+ config.url = $REGIS_API['url']
7
+ config.username = $REGIS_API['username']
8
+ config.password = $REGIS_API['password']
9
+ config.cache = Regis::Cache.new(Dalli::Client.new('localhost:11211', { :namespace => "regis", :compress => true, :expires_in => 3600 }))
10
+ end
@@ -0,0 +1,3 @@
1
+ url: 'https://some.url.com'
2
+ username: "some_username"
3
+ password: "some_password"
@@ -0,0 +1,2 @@
1
+ reporting_term: "some_reporting_term"
2
+ section_uuid: "some_section_uuid"
@@ -0,0 +1,22 @@
1
+ Feature: regis api can connect
2
+ In order to use the REGIS api
3
+ I want to be able to connect
4
+
5
+ Scenario: search sections
6
+ When I search for sections
7
+ Then I should receive a list of sections
8
+
9
+ Scenario: retrieve section
10
+ When I ask for a section
11
+ Then I should receive the section I asked for
12
+
13
+ Scenario: section values are populated
14
+ When I ask for a section
15
+ Then I should have populated section values
16
+
17
+ Scenario: api is cached
18
+ When I reset the section cache
19
+ And I ask for a section
20
+ Then I should receive the section I asked for
21
+ When I ask for a section
22
+ Then I should have a cached response
@@ -0,0 +1,32 @@
1
+ When /^I search for sections$/ do
2
+ @response = Regis.client.sections_get_by_reporting_term($REGIS_TEST_VALUES['reporting_term'])
3
+ end
4
+
5
+ Then /^I should receive a list of sections$/ do
6
+ expect(@response.sections.count > 0).to be true
7
+ end
8
+
9
+ When /^I reset the section cache$/ do
10
+ Regis.client.configuration.cache.delete("/Section/Admin/#{$REGIS_TEST_VALUES['section_uuid']}?format=json")
11
+ end
12
+
13
+ When /^I ask for a section$/ do
14
+ @response = Regis.client.section_get_by_uuid($REGIS_TEST_VALUES['section_uuid'])
15
+ end
16
+
17
+ Then /^I should receive the section I asked for$/ do
18
+ expect(@response.section.uuid == $REGIS_TEST_VALUES['section_uuid']).to be true
19
+ end
20
+
21
+ Then /^I should have populated section values$/ do
22
+ expect(@response.section.uuid).not_to be_empty
23
+ expect(@response.section.reporting_term).not_to be_empty
24
+ expect(@response.section.course_name).not_to be_empty
25
+ expect(@response.section.title).not_to be_empty
26
+ expect(@response.section.min_credits).to be > 0
27
+ end
28
+
29
+ Then /^I should have a cached response$/ do
30
+ response = Regis.client.configuration.cache.read("/Section/Admin/#{$REGIS_TEST_VALUES['section_uuid']}?format=json")
31
+ expect(response).to be_instance_of(Faraday::Response)
32
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ require 'yaml'
5
+
6
+ require_relative '../../config/initializers/regis'
7
+
8
+ $REGIS_TEST_VALUES = YAML.load_file("features/config/test_values.yml")
data/lib/regis.rb ADDED
@@ -0,0 +1,11 @@
1
+ # Regis API
2
+ # shamelessly cloned from https://github.com/Yelp/yelp-ruby
3
+
4
+ require 'regis/version'
5
+ require 'regis/client'
6
+
7
+ module Regis
8
+ def self.client
9
+ @client ||= Regis::Client.new
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module Regis
2
+ class Cache
3
+ attr_accessor :store
4
+
5
+ def initialize(store)
6
+ @store = store
7
+ end
8
+
9
+ def write(key, value)
10
+ @store.set(key, value)
11
+ end
12
+
13
+ def read(key)
14
+ @store.get(key)
15
+ end
16
+
17
+ def delete(key)
18
+ @store.delete(key)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,78 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'faraday-cookie_jar'
4
+
5
+ require 'dalli'
6
+
7
+ require 'regis/cache'
8
+ require 'regis/configuration'
9
+ require 'regis/endpoint/section'
10
+ require 'regis/endpoint/sections'
11
+
12
+ module Regis
13
+ class Client
14
+ REQUEST_CLASSES = [ Regis::Endpoint::Section, Regis::Endpoint::Sections ]
15
+
16
+ attr_reader :configuration
17
+
18
+ def initialize(options = nil)
19
+ @configuration = nil
20
+ define_request_methods
21
+
22
+ unless options.nil?
23
+ @configuration = Configuration.new(options)
24
+ end
25
+ end
26
+
27
+ def configure
28
+ @configuration = Configuration.new
29
+ yield(@configuration)
30
+ end
31
+
32
+ def connection
33
+ return @connection if instance_variable_defined?(:@connection)
34
+ @connection = Faraday.new(@configuration.url, :ssl => {:verify => false}) do |faraday|
35
+ faraday.basic_auth(@configuration.username, @configuration.password)
36
+ faraday.request :json
37
+
38
+ faraday.response :json, :content_type => /\bjson$/
39
+ #faraday.response :logger
40
+
41
+ faraday.response :caching do
42
+ @configuration.cache
43
+ end
44
+
45
+ faraday.use :cookie_jar #preserve the servicestack session
46
+ faraday.adapter Faraday.default_adapter
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ # This goes through each endpoint class and creates singletone methods
53
+ # on the client that query those classes. We do this to avoid possible
54
+ # namespace collisions in the future when adding new classes
55
+ def define_request_methods
56
+ REQUEST_CLASSES.each do |request_class|
57
+ endpoint_instance = request_class.new(self)
58
+ create_methods_from_instance(endpoint_instance)
59
+ end
60
+ end
61
+
62
+ # Loop through all of the endpoint instances' public singleton methods to
63
+ # add the method to client
64
+ def create_methods_from_instance(instance)
65
+ instance.public_methods(false).each do |method_name|
66
+ add_method(instance, method_name)
67
+ end
68
+ end
69
+
70
+ # Define the method on the client and send it to the endpoint instance
71
+ # with the args passed in
72
+ def add_method(instance, method_name)
73
+ define_singleton_method(method_name) do |*args|
74
+ instance.public_send(method_name, *args)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,8 @@
1
+ module Regis
2
+ class Configuration
3
+ attr_accessor :url
4
+ attr_accessor :username
5
+ attr_accessor :password
6
+ attr_accessor :cache
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'regis/responses/section'
3
+
4
+ module Regis
5
+ module Endpoint
6
+ class Section
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def section_get_by_uuid(uuid)
12
+ response = @client.connection.get "/Section/Admin/#{uuid}", { :format => 'json' }
13
+ Response::Section.new(response.body)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'regis/responses/sections'
3
+
4
+ module Regis
5
+ module Endpoint
6
+ class Sections
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def sections_get_by_reporting_term(reporting_term)
12
+ response = @client.connection.get "/Sections/Admin/#{reporting_term}", { :format => 'json' }
13
+ Response::Sections.new(response.body)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Regis
2
+ module Response
3
+ class Base
4
+ def initialize(json)
5
+ return if json.nil?
6
+
7
+ json.each do |key, value|
8
+ instance_variable_set("@#{key}", value)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def parse(json, klass)
15
+ return json.collect { |j| klass.new(j) } if json.is_a?(Array)
16
+ return klass.new(json) if json
17
+ nil
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'regis/responses/base'
2
+
3
+ module Regis
4
+ module Response
5
+ module Model
6
+ class Section < Response::Base
7
+ attr_reader :uuid
8
+ attr_reader :course_name
9
+ attr_reader :title
10
+ attr_reader :location
11
+ attr_reader :room
12
+
13
+ attr_reader :is_audio
14
+ attr_reader :is_oncampus
15
+
16
+ attr_reader :start_date
17
+ attr_reader :end_date
18
+ attr_reader :meeting_days
19
+ attr_reader :start_times
20
+ attr_reader :end_times
21
+
22
+ attr_reader :is_weekend
23
+ attr_reader :is_weekday
24
+ attr_reader :is_evening
25
+ attr_reader :is_waitlist
26
+
27
+ attr_reader :is_unlisted
28
+
29
+ attr_reader :reporting_term
30
+ attr_reader :min_credits
31
+ attr_reader :max_credits
32
+ attr_reader :is_pass_fail
33
+
34
+ def initialize(json)
35
+ super(json)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ require 'regis/responses/base'
2
+ require 'regis/responses/models/section'
3
+
4
+ module Regis
5
+ module Response
6
+ class Section < Base
7
+ attr_reader :section
8
+
9
+ def initialize(json)
10
+ @section = parse(json, Model::Section)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'regis/responses/base'
2
+ require 'regis/responses/models/section'
3
+
4
+ module Regis
5
+ module Response
6
+ class Sections < Base
7
+ attr_reader :sections
8
+
9
+ def initialize(json)
10
+ super(json)
11
+
12
+ @sections = parse(@sections, Model::Section)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Regis
2
+ VERSION = "0.0.3"
3
+ end
data/regis.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'regis/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'regis'
8
+ s.required_ruby_version = '>= 1.9.3'
9
+ s.add_runtime_dependency 'faraday', '~> 0.8', '>= 0.8.0'
10
+ s.add_runtime_dependency 'faraday_middleware', '~> 0.8', '>= 0.8.0'
11
+ s.add_runtime_dependency 'faraday-cookie_jar', '~> 0.0.6', '>= 0.0.6'
12
+ s.add_runtime_dependency 'faraday-http-cache', '~> 1.2', '>= 1.2.2'
13
+ s.add_runtime_dependency 'dalli', '~> 2.7', '>= 2.7.0'
14
+ s.add_development_dependency 'cucumber', '~> 1.3', '>= 1.3.20'
15
+ s.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
16
+ s.date = '2016-01-15'
17
+ s.summary = "Ruby API connector"
18
+ s.description = "The REGIS API as typed models"
19
+ s.authors = ["Cameron Tucker"]
20
+ s.email = 'ctucker@regent-college.edu'
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {features}/*`.split("\n")
23
+ s.homepage = 'https://github.com/RegentCollege/regis-ruby'
24
+ s.license = 'AGPL'
25
+ s.version = Regis::VERSION
26
+ s.require_paths = ["lib"]
27
+ s.test_files = s.files.grep(%r{^(features)/})
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Tucker
@@ -50,6 +50,66 @@ dependencies:
50
50
  - - ! '>='
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.8.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: faraday-cookie_jar
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: 0.0.6
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.0.6
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.6
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 0.0.6
73
+ - !ruby/object:Gem::Dependency
74
+ name: faraday-http-cache
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: '1.2'
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.2
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: 1.2.2
93
+ - !ruby/object:Gem::Dependency
94
+ name: dalli
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ~>
98
+ - !ruby/object:Gem::Version
99
+ version: '2.7'
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: 2.7.0
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '2.7'
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: 2.7.0
53
113
  - !ruby/object:Gem::Dependency
54
114
  name: cucumber
55
115
  requirement: !ruby/object:Gem::Requirement
@@ -97,8 +157,28 @@ extensions: []
97
157
  extra_rdoc_files: []
98
158
  files:
99
159
  - .gitignore
160
+ - Gemfile
100
161
  - LICENSE
101
162
  - README.md
163
+ - Rakefile
164
+ - config/initializers/regis.rb
165
+ - config/regis_api.example.yml
166
+ - features/config/test_values.example.yml
167
+ - features/regis_api.feature
168
+ - features/step_definitions/api_steps.rb
169
+ - features/support/env.rb
170
+ - lib/regis.rb
171
+ - lib/regis/cache.rb
172
+ - lib/regis/client.rb
173
+ - lib/regis/configuration.rb
174
+ - lib/regis/endpoint/section.rb
175
+ - lib/regis/endpoint/sections.rb
176
+ - lib/regis/responses/base.rb
177
+ - lib/regis/responses/models/section.rb
178
+ - lib/regis/responses/section.rb
179
+ - lib/regis/responses/sections.rb
180
+ - lib/regis/version.rb
181
+ - regis.gemspec
102
182
  homepage: https://github.com/RegentCollege/regis-ruby
103
183
  licenses:
104
184
  - AGPL
@@ -123,4 +203,8 @@ rubygems_version: 2.4.8
123
203
  signing_key:
124
204
  specification_version: 4
125
205
  summary: Ruby API connector
126
- test_files: []
206
+ test_files:
207
+ - features/config/test_values.example.yml
208
+ - features/regis_api.feature
209
+ - features/step_definitions/api_steps.rb
210
+ - features/support/env.rb