petfinder_ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/petfinder_ruby.rb +54 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 84e706e6b2c3a3a133c02395ad79c056188464c365ad29b9bfc65cbd83a6ec81
4
+ data.tar.gz: 94be625b03f463c1b6cd316ee28f6f668569f497bcfd3bf35f543b50185a67e8
5
+ SHA512:
6
+ metadata.gz: b44d4c9fd191c85f65bc272dc1136b08423c0d99273487dcfe651de2d4fc836378dad9ad777af02db68b2dc9d38e7b7aa06da35cb49b130b26af8d2f54ab1c5d
7
+ data.tar.gz: 11b6c815a2d4025bbb825345bcfef8013e3a69f749510605de165ba51567c687952282e3469a360170f8ae874773e8440c95283f3bf637e7c2eab931544e3f2b
@@ -0,0 +1,54 @@
1
+ require 'unirest'
2
+
3
+ module Petfinder
4
+ class << self
5
+ attr_accessor :configuration
6
+ end
7
+
8
+ def self.configure
9
+ self.configuration ||= Configuration.new
10
+ yield(configuration)
11
+ end
12
+
13
+ class Configuration
14
+ attr_accessor :client_id, :client_secret, :access_token, :token_expires_at
15
+ end
16
+
17
+ class Client
18
+ def self.get_token
19
+ response = Unirest.post("https://api.petfinder.com/v2/oauth2/token",
20
+ parameters: {
21
+ "grant_type" => "client_credentials",
22
+ "client_id" => "#{Petfinder.configuration.client_id}",
23
+ "client_secret" => "#{Petfinder.configuration.client_secret}"
24
+ }
25
+ )
26
+ Petfinder.configuration.access_token = response.body["access_token"]
27
+ Petfinder.configuration.token_expires_at = Time.now + 3560
28
+ end
29
+
30
+ def self.get_adoptable_animals_by_organization(org_id)
31
+ check_token
32
+ response = Unirest.get("https://api.petfinder.com/v2/animals",
33
+ headers: {"Authorization" => "Bearer #{Petfinder.configuration.access_token}"},
34
+ parameters: { "organization" => org_id,
35
+ "status" => "adoptable"
36
+ }
37
+ )
38
+ response.body
39
+ end
40
+
41
+ def self.get_organization(org_id)
42
+ check_token
43
+ response = Unirest.get("https://api.petfinder.com/v2/organizations/#{org_id}",
44
+ headers: {"Authorization" => "Bearer #{Petfinder.configuration.access_token}"})
45
+ response.body
46
+ end
47
+
48
+ def self.check_token
49
+ if Petfinder.configuration.access_token == nil || Petfinder.configuration.token_expires_at < Time.now
50
+ get_token
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: petfinder_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mitch Fischer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unirest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/petfinder_ruby.rb
34
+ homepage:
35
+ licenses: []
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.7.7
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Test Gem that assists with interacting with the Petfinder REST API. For a
57
+ more robust gem, see https://github.com/ehutzelman/petfinder
58
+ test_files: []