PetSearch 0.0.7.1 → 0.0.7.7

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTczNWExYjMwZjI0ZjM4YTFmODMwYjc2NGE4NDU0NGE3YmM1ZWI4OQ==
4
+ ZjlmYTIzNDVhMzUwNDc1NWFiMDM1YWFkMGI1NDY4NjQ2OGY5MDM5MA==
5
5
  data.tar.gz: !binary |-
6
- Mzc4OWFjNDMzZjUxN2YxYjcwNjFiN2VlZDZjYTg0NTVlMzQ2YzM4Mw==
6
+ OTdlZTA4MTMyYjY1ZGM4ZDZiMzA3YmM3YmRmODkxZGFlMTg2MDZhMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmJjMDEyOTM1ZDE0YWIyMzQzOGY4ZDNlODdhZDA3OGQyNzIyNTEyYTljZTJh
10
- ZDJmZWZmYjg5YjE0OThlY2IxMDQ5Mjg3ZjNiYjI0MjMxY2YwZDU3ZWZkYTVj
11
- NzYzZDA0ZmMxOWMxZjJmNDE1NjRlYTAyMDY2Mjc3N2JiYmNiZWY=
9
+ Y2I3M2YxYTcwZWMwYmM5ZDA2MDc5NmEyZWUxNmExZmEyNDlkOWJmZGQwYjZk
10
+ YWJmNmJhNWYwNjk5MTRjMGRhZmFjMDg0NjE0MzRmMDg0ZThhMjQwNTM4MTA0
11
+ M2MwOWExMTczYWMyOTE4N2Q5NmFlM2M3YjJiOTZiZjcwMDYxZmI=
12
12
  data.tar.gz: !binary |-
13
- OGU0NDY1YmI5OGIxMjViZTI5ZmQyZjU2YTIwYjhmYzNmOTI1ZjViODMzMWFh
14
- OGE5OGU2MWIyYjNlZjhlZTljMzIwNWZhYTc5Njc5YTA5MzNkOGIxNDFiNDcw
15
- YTU5Mzc4NGQ2YzMxM2E4ODdhMzc3YzkwYmYzNzczN2RjNmE0MzU=
13
+ ZGM2NjY5OTJjYjcwOGRjY2U1YTJhOTM3NDEyNTA1OTlkMDY3NTBiZTg0YTRm
14
+ YWRlOTdjNzcwOWVkM2E1Y2RlMzQ0YTA5MjYyOTRlMjdiMWUyODRiYmQ2NWZk
15
+ YTg5MDI4ZWRkYTk2MDJmNDQ3ZTlmYjhlZWZjZGM5YWMyYTA3Njg=
@@ -23,12 +23,13 @@ class PetSearch
23
23
 
24
24
 
25
25
  def self.init_options(*args)
26
+ @@options = Hash.new
26
27
  begin
27
28
  @@options[:breeds] = args.grep(/[Bb]reeds/).first.downcase.match(/(?<=breeds=).*/)[0].split(',') if args.grep(/[Bb]reeds/).first
28
29
  @@options[:animal] = args.grep(/[Dd]og|[Cc]at|[Bb]ird|[Rr]eptile|[Hh]orse|[Pp]ig|[Bb]arnyard|[Ss]mallfurry/).first
29
30
  @@options[:age] = args.grep(/[Bb]aby|[Yy]oung|[Aa]dult|[Ss]enior/).first
30
31
  @@options[:location] = args.grep(/[1..9]/).first
31
- @@options[:sex] = args.grep(/[Ss]ex/).first.downcase.match(/(?<=sex=).*/)[0] if args.grep(/[Ss]ex/).first
32
+ @@options[:sex] = args.grep(/[Ss]ex/).first.downcase.match(/(?<=sex=).*/)[0].upcase if args.grep(/[Ss]ex/).first
32
33
  @@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
33
34
  case (@@options[:size])
34
35
  when 'sm'
@@ -1,10 +1,13 @@
1
1
  require 'date'
2
2
  require 'json'
3
- #require_relative '../petsearch'
3
+ require 'nokogiri'
4
+ require 'action_view'
5
+ require 'htmlentities'
4
6
 
5
7
  class Pet
6
- attr_accessor :name, :age, :sex, :size, :petfinder_id, :shelter_id, :images, :breeds, :status, :contact, :description, :last_update, :options
7
-
8
+ attr_accessor :name, :age, :sex, :size, :petfinder_id, :shelter_id, :shelter_pet_id, :images, :breeds, :status, :contact, :description, :last_update, :options
9
+ cattr_accessor :pets
10
+ @@pets = Array.new
8
11
  def initialize
9
12
  @name = ''
10
13
  @age = ''
@@ -18,13 +21,70 @@ class Pet
18
21
  @status = ''
19
22
  @description = ''
20
23
  @last_update = ''
21
- @options = ''
24
+ @options = []
25
+ @shelter_pet_id = {}
26
+ end
27
+
28
+ def self.pets
29
+ @@pets
30
+ end
31
+
32
+
33
+ def self.make_search(options)
34
+ animal = options.match(/animal=(.*?)&/).nil? ? "ERROR" : options.match(/animal=(.*?)&/)[1]
35
+ br=options.match(/&breeds=(.*?)&/).nil? ? [] : options.match(/&breeds=(.*?)&/)[1]
36
+ breeds = br.split(',')
37
+ offset = options.match(/&off(.*?)&/).nil? ? "" : options.match(/&off(.*?)&/)[1]
38
+ count = options.match(/&ct(.*?)&/).nil? ? "" : options.match(/&ct(.*?)&/)[1]
39
+ sex = options.match(/&sex=(.*?)&/).nil? ? "" : options.match(/&sex=(.*?)&/)[1]
40
+ location = options.match(/((?:\d\d+)+)/).nil? ? "" : options.match(/((?:\d\d+)+)/)
41
+ PetSearch.init_options("#{animal}", "#{location}", "ct#{count}", "#{sex}", "off#{offset}")
42
+ PetSearch.options[:breeds] = breeds
43
+ result = PetSearch.search
44
+ make_pet(result)
22
45
  end
23
46
 
47
+ def self.make_pet(result)
48
+ @@pets = []
49
+ result[0]['petfinder']['pets']['pet'].each do |pet|
50
+ p = Pet.new
51
+ if pet['options']['option'].class == Hash
52
+ p.options << pet['options']['option']['$t']
53
+ else p.options = pet['options']['option'].map { |t|
54
+ t['$t'] }
55
+ end
56
+ if pet['breeds']['breed'].class == Hash
57
+ p.options << pet['breeds']['breed']['$t']
58
+ else
59
+ p.breeds = pet['breeds']['breed'].map { |t|
60
+ t['$t']}
61
+ end
62
+ p.shelter_pet_id = pet['shelterPetId'] ? pet['shelterPetId']['$t'] : ""
63
+ p.status = pet['status']['$t']
64
+ p.name = pet['name']['$t']
65
+ p.contact[:email] = pet['contact']['email']['$t']
66
+ p.contact[:zip] = pet['contact']['zip']['$t']
67
+ p.contact[:city] = pet['contact']['city']['$t']
68
+ p.contact[:fax] = pet['contact']['fax']['$t']
69
+ p.contact[:address1] = pet['contact']['address1']['$t']
70
+ p.contact[:phone] = pet['contact']['phone']['$t']
71
+ p.contact[:state] = pet['contact']['state']['$t']
72
+ p.description=HTMLEntities.new.decode(ActionView::Base.full_sanitizer.sanitize(pet['description']['$t']))
73
+ p.sex = pet['sex']['$t']
74
+ p.shelter_id = pet['shelterId']['$t']
75
+ p.size = pet['size']['$t']
76
+ p.age = pet['age']['$t']
77
+ p.last_update = Date.parse((pet['lastUpdate']['$t'].split('T'))[0])
78
+ p.images = pet['media']['photos']['photo'].map { |photo|
79
+ photo['$t']
80
+ }
81
+ p.petfinder_id = pet['id']['$t']
82
+ @@pets << p
83
+
84
+ end
85
+ return @@pets
86
+ end
24
87
 
25
- # PetClient.get_token()
26
- # PetSearch.init_options('sex=m', 'dog', 'senior', '94123', 'breeds=pug,vizsla', 'ct5', 'sm')
27
- # binding.pry
88
+ end
28
89
 
29
90
 
30
- end
@@ -4,8 +4,6 @@ require 'digest/md5'
4
4
  require 'nokogiri'
5
5
  require 'date'
6
6
 
7
-
8
-
9
7
  class PetClient
10
8
 
11
9
  @@token_hash = Hash.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: PetSearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.1
4
+ version: 0.0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lior Bendat, Sharif Hadidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2013-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlentities
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: nokogiri
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ! '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: htmlentities
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: This gem is a simple interface for the PetFinder API, which is notoriously
56
84
  difficult to deal with. I've attempted to make people's lives easier.
57
85
  email: liorbendat@gmail.com