PetSearch 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/petsearch.rb +39 -3
- data/lib/petsearch/pet.rb +26 -0
- data/lib/petsearch/petclient.rb +3 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGRkOGQ3NDBhZTI5NmUyNTljZjM1ZjQxMzI0YzdjZjU3YzdkNDUzOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjNiNWQ5NDAxNzM5NTUxOGUxYzFhZGM2YTNkMzYyNTliY2E3Nzk2Nw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDkwNWI2M2MzNzU1MWIwOWU2ZTYwMjUwMWQ0ZmYwZmRlYTE1Y2YzMGViNzAy
|
10
|
+
MjQ0YmU4Y2U5NTAzNzY4NGYyOWQyZWIzZGIwZjYyNmEyNzY2ZjE4ZjQ0ODc5
|
11
|
+
Zjk4YzQ4OTM3NTU2ODJiN2FhMjdmZmM4ZGI5OTk4ZjkyMzc1YTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZThjYzVjYWE1NmI1YzZiNzA4MDNiYmNiZmM2MTJhZGExZWY2YTc4ZTkwNmQ4
|
14
|
+
ZjgzOWZjYmM4ZjM2YzMzNDM1MTA5ZWY4ZjcxZGUyOGY1OWE5YWE4NjZkZTFm
|
15
|
+
NWFjYjc0NmE2YzE2ZmQ3YTI3ODIyMjFhNmI4NmZhMTYyMjBkZWQ=
|
data/lib/petsearch.rb
CHANGED
@@ -3,11 +3,12 @@ require 'open-uri'
|
|
3
3
|
require 'digest/md5'
|
4
4
|
require 'nokogiri'
|
5
5
|
require 'date'
|
6
|
-
require 'petsearch/
|
6
|
+
require './petsearch/petclient'
|
7
|
+
require './petsearch/pet'
|
7
8
|
|
8
9
|
class PetSearch
|
9
10
|
attr_accessor :dog, :cat, :bird, :reptile, :horse, :pig, :barnyard, :smallfurry
|
10
|
-
|
11
|
+
@@options = Hash.new
|
11
12
|
def initialize
|
12
13
|
@dog = {:name => 'dog', :breeds => []}
|
13
14
|
@cat = {:name => 'cat', :breeds => []}
|
@@ -20,7 +21,42 @@ class PetSearch
|
|
20
21
|
end
|
21
22
|
|
22
23
|
|
23
|
-
|
24
|
+
def self.init_options(*args)
|
25
|
+
begin
|
26
|
+
@@options[:breeds] = args.grep(/[Bb]reeds/).first.downcase.match(/(?<=breeds=).*/)[0].split(',') if args.grep(/[Bb]reeds/).first
|
27
|
+
@@options[:animal] = args.grep(/[Dd]og|[Cc]at|[Bb]ird|[Rr]eptile|[Hh]orse|[Pp]ig|[Bb]arnyard|[Ss]mallfurry/).first
|
28
|
+
@@options[:age] = args.grep(/[Bb]aby|[Yy]oung|[Aa]dult|[Ss]enior/).first
|
29
|
+
@@options[:location] = args.grep(/[1..9]/).first
|
30
|
+
@@options[:sex] = args.grep(/[Mm]|[Ff]/).first.upcase if args.grep(/[Mm]|[Ff]/)
|
31
|
+
@@options[:size] = args.grep(/[Ss]m|[Mm]dm|[Ll]rg|[Xx]l/).first.downcase if args.grep(/[Ss]m|[Mm]dm|[Ll]rg|[Xx]l/).first
|
32
|
+
case (@@options[:size])
|
33
|
+
when 'sm'
|
34
|
+
@@options[:size] = 'S'
|
35
|
+
when 'mdm'
|
36
|
+
@@options[:size] = 'M'
|
37
|
+
when 'lrg'
|
38
|
+
@@options[:size] = 'L'
|
39
|
+
when 'xl'
|
40
|
+
@@options[:size] = 'XL'
|
41
|
+
end
|
42
|
+
@@options[:random] = args.grep(/[Tt]rue|[Ff]alse/).first
|
43
|
+
@@options[:offset] = args.grep(/[Oo]ff/).first.downcase.match(/(?<=off).*/)[0] if args.grep(/[Oo]ff/).first
|
44
|
+
@@options[:count] = args.grep(/[Ct]/).first.downcase.match(/(?<=ct).*/)[0] if args.grep(/[Ct]/).first
|
45
|
+
rescue NoMethodError
|
46
|
+
puts "You have an error in your parameters"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.options
|
51
|
+
@@options
|
52
|
+
end
|
24
53
|
|
54
|
+
def self.search
|
55
|
+
PetClient.search_listings(@@options)
|
56
|
+
end
|
25
57
|
|
58
|
+
def self.get_token
|
59
|
+
PetClient.get_token
|
60
|
+
end
|
61
|
+
end
|
26
62
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'json'
|
3
|
+
require_relative '../petsearch'
|
4
|
+
|
5
|
+
class Pet
|
6
|
+
attr_accessor :name, :age, :sex, :size, :petfinder_id, :shelter_id, :images, :breeds, :status, :contact, :description, :last_update, :options
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@name = ''
|
10
|
+
@age = ''
|
11
|
+
@sex = ''
|
12
|
+
@size = ''
|
13
|
+
@petfinder_id = ''
|
14
|
+
@shelter_id = ''
|
15
|
+
@images = []
|
16
|
+
@breeds = []
|
17
|
+
@contact = {}
|
18
|
+
@status = ''
|
19
|
+
@description = ''
|
20
|
+
@last_update = ''
|
21
|
+
@options = ''
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
end
|
data/lib/petsearch/petclient.rb
CHANGED
@@ -63,8 +63,8 @@ class PetClient
|
|
63
63
|
result = build_url(search_string, nil, id)
|
64
64
|
end
|
65
65
|
|
66
|
-
def self.search_listings(
|
67
|
-
animal = (
|
66
|
+
def self.search_listings(options={})
|
67
|
+
animal = (options[:animal].nil?) ? false : options[:animal]
|
68
68
|
breeds = (options[:breeds].nil? || options[:breeds].empty?) ? "" : options[:breeds]
|
69
69
|
size = options[:size].nil? ? "" : options[:size]
|
70
70
|
sex = options[:sex].nil? ? "" : options[:sex]
|
@@ -100,6 +100,7 @@ class PetClient
|
|
100
100
|
result_set << build_url(search_string)
|
101
101
|
end
|
102
102
|
end
|
103
|
+
return result_set
|
103
104
|
end
|
104
105
|
|
105
106
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: PetSearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lior Bendat, Sharif Hadidi
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- lib/petsearch.rb
|
63
63
|
- lib/petsearch/petclient.rb
|
64
|
+
- lib/petsearch/pet.rb
|
64
65
|
homepage: https://github.com/lbendat/PetfinderAPIGem
|
65
66
|
licenses:
|
66
67
|
- Open-Source
|