Class: Olya::BibblioAuth
- Inherits:
-
Object
- Object
- Olya::BibblioAuth
- Defined in:
- lib/olya.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#bibblio_auth ⇒ Object
Returns the value of attribute bibblio_auth.
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #auth_to_olya(base_url) ⇒ Object
- #headers ⇒ Object
-
#initialize(config_yml, url = "https://api.bibblio.org/token") ⇒ BibblioAuth
constructor
A new instance of BibblioAuth.
- #parse_yaml(yaml_file) ⇒ Object
Constructor Details
#initialize(config_yml, url = "https://api.bibblio.org/token") ⇒ BibblioAuth
Returns a new instance of BibblioAuth.
12 13 14 15 |
# File 'lib/olya.rb', line 12 def initialize(config_yml, url = "https://api.bibblio.org/token") @bibblio_auth ||= parse_yaml(config_yml) @base_url ||= url end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
10 11 12 |
# File 'lib/olya.rb', line 10 def base_url @base_url end |
#bibblio_auth ⇒ Object
Returns the value of attribute bibblio_auth.
10 11 12 |
# File 'lib/olya.rb', line 10 def bibblio_auth @bibblio_auth end |
#session ⇒ Object
Returns the value of attribute session.
10 11 12 |
# File 'lib/olya.rb', line 10 def session @session end |
Instance Method Details
#auth_to_olya(base_url) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/olya.rb', line 29 def auth_to_olya(base_url) values = "client_id=#{bibblio_auth["credentials"]["client_id"]}&client_secret=#{bibblio_auth["credentials"]["client_secret"]}" begin response = RestClient.post base_url, values, headers rescue => e # handle 401 402 403 response = {} end response = JSON.parse(response) end |
#headers ⇒ Object
25 26 27 |
# File 'lib/olya.rb', line 25 def headers @bibblio_auth[:headers] ||= Hash.new(:content_type => 'application/x-www-form-urlencoded') end |
#parse_yaml(yaml_file) ⇒ Object
17 18 19 |
# File 'lib/olya.rb', line 17 def parse_yaml(yaml_file) YAML.load_file(File.join(Dir.pwd, yaml_file)) end |