lolcation_client 0.1.4 → 0.1.5
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,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: db6234d327df630f577bd8197571cc9d82bbf68f
         | 
| 4 | 
            +
              data.tar.gz: 1cb4d0b5bea591cccf8a46d1130882f53bda1293
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2ffbf03b2f04f554a9b5636f78f39317afe258e3bb736c643e2eea058a6414008f7c863e9bbdee02eca3777ba752c5ed7a1a932ace45eb3301fa217125e2527b
         | 
| 7 | 
            +
              data.tar.gz: 25428aae5bdd403434efd1b653c18abeed5c8c686a7acaaf05cb1d0619bb4ccf6e6a5226e43eb5f9ee3699204aae22e82af7e982bf57ef414d9a51ce75e6bac9
         | 
| @@ -7,22 +7,23 @@ module LolcationClient | |
| 7 7 |  | 
| 8 8 | 
             
                def self.included(model)
         | 
| 9 9 | 
             
                  model.send(:after_validation) do
         | 
| 10 | 
            -
                    if self. | 
| 11 | 
            -
                      response =  | 
| 10 | 
            +
                    if self.persisted?
         | 
| 11 | 
            +
                      response = update_on_lolcation_server
         | 
| 12 12 | 
             
                    else
         | 
| 13 | 
            -
                      response =  | 
| 13 | 
            +
                      response = create_on_lolcation_server
         | 
| 14 14 | 
             
                    end
         | 
| 15 15 |  | 
| 16 | 
            -
                     | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 16 | 
            +
                    json = JSON.parse(response.body, object_class: OpenStruct)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    if json.error.present?
         | 
| 19 | 
            +
                      self.errors.add(:base, json.error)
         | 
| 19 20 | 
             
                      false
         | 
| 20 | 
            -
                    elsif  | 
| 21 | 
            -
                      self.lolcation_id =  | 
| 22 | 
            -
                      self.lolcation_latitude =  | 
| 23 | 
            -
                      self.lolcation_longitude =  | 
| 21 | 
            +
                    elsif json.localization.present?
         | 
| 22 | 
            +
                      self.lolcation_id = json.localization.id
         | 
| 23 | 
            +
                      self.lolcation_latitude = json.localization.latitude
         | 
| 24 | 
            +
                      self.lolcation_longitude = json.localization.longitude
         | 
| 24 25 | 
             
                    else
         | 
| 25 | 
            -
                       | 
| 26 | 
            +
                      json.map {|error, message| self.errors.add("lolcation_#{error}", message[0])}
         | 
| 26 27 | 
             
                      false
         | 
| 27 28 | 
             
                    end
         | 
| 28 29 | 
             
                  end
         | 
| @@ -34,9 +35,10 @@ module LolcationClient | |
| 34 35 | 
             
                  self.class.try(:lolcation_custom_fields) || []
         | 
| 35 36 | 
             
                end
         | 
| 36 37 |  | 
| 37 | 
            -
                def  | 
| 38 | 
            +
                def build_custom_fields
         | 
| 38 39 | 
             
                  attributes = custom_fields.map {|attribute| {attribute => self.try(attribute)}}
         | 
| 39 | 
            -
                  hash | 
| 40 | 
            +
                  hash       = {}
         | 
| 41 | 
            +
             | 
| 40 42 | 
             
                  attributes.each do |attribute|
         | 
| 41 43 | 
             
                    attribute.each do |key, value|
         | 
| 42 44 | 
             
                      hash[key] = value
         | 
| @@ -46,40 +48,41 @@ module LolcationClient | |
| 46 48 | 
             
                  hash
         | 
| 47 49 | 
             
                end
         | 
| 48 50 |  | 
| 49 | 
            -
                def  | 
| 51 | 
            +
                def build_params
         | 
| 50 52 | 
             
                  {
         | 
| 51 53 | 
             
                    localization: {
         | 
| 52 | 
            -
                      latitude: | 
| 53 | 
            -
                      longitude: | 
| 54 | 
            -
                      name: | 
| 55 | 
            -
                      address_street: | 
| 54 | 
            +
                      latitude:             self.try(:lolcation_latitude),
         | 
| 55 | 
            +
                      longitude:            self.try(:lolcation_longitude),
         | 
| 56 | 
            +
                      name:                 self.try(:lolcation_name),
         | 
| 57 | 
            +
                      address_street:       self.try(:lolcation_address_street),
         | 
| 56 58 | 
             
                      address_neighborhood: self.try(:lolcation_address_neighborhood),
         | 
| 57 | 
            -
                      address_city: | 
| 58 | 
            -
                      address_state: | 
| 59 | 
            -
                      address_number: | 
| 60 | 
            -
                       | 
| 59 | 
            +
                      address_city:         self.try(:lolcation_address_city),
         | 
| 60 | 
            +
                      address_state:        self.try(:lolcation_address_state),
         | 
| 61 | 
            +
                      address_number:       self.try(:lolcation_address_number),
         | 
| 62 | 
            +
                      address_zipcode:      self.try(:lolcation_address_zipcode),
         | 
| 63 | 
            +
                      #custom_fields:        build_custom_fields
         | 
| 61 64 | 
             
                    },
         | 
| 62 65 | 
             
                    sandbox: sandbox?
         | 
| 63 | 
            -
                  }
         | 
| 66 | 
            +
                  }.to_json
         | 
| 64 67 | 
             
                end
         | 
| 65 68 |  | 
| 66 | 
            -
                def  | 
| 69 | 
            +
                def create_on_lolcation_server
         | 
| 67 70 | 
             
                  url = LolcationClient::Configurations::URL
         | 
| 68 71 | 
             
                  conn = Faraday.new(url: url)
         | 
| 69 72 | 
             
                  conn.post do |r|
         | 
| 70 73 | 
             
                    r.headers["X-Token"] = token
         | 
| 71 74 | 
             
                    r.headers["Content-Type"] = "application/json"
         | 
| 72 | 
            -
                    r.body =  | 
| 75 | 
            +
                    r.body = build_params
         | 
| 73 76 | 
             
                  end
         | 
| 74 77 | 
             
                end
         | 
| 75 78 |  | 
| 76 | 
            -
                def  | 
| 79 | 
            +
                def update_on_lolcation_server
         | 
| 77 80 | 
             
                  url = LolcationClient::Configurations::URL
         | 
| 78 81 | 
             
                  conn = Faraday.new(url: "#{url}/#{self.lolcation_id}")
         | 
| 79 82 | 
             
                  conn.put do |r|
         | 
| 80 83 | 
             
                    r.headers["X-Token"] = token
         | 
| 81 84 | 
             
                    r.headers["Content-Type"] = "application/json"
         | 
| 82 | 
            -
                    r.body =  | 
| 85 | 
            +
                    r.body = build_params
         | 
| 83 86 | 
             
                  end
         | 
| 84 87 | 
             
                end
         | 
| 85 88 | 
             
              end
         | 
| @@ -3,8 +3,16 @@ module LolcationClient | |
| 3 3 | 
             
                def lolcation_fields(options = {})
         | 
| 4 4 | 
             
                  self.class_eval do
         | 
| 5 5 | 
             
                    before_validation do
         | 
| 6 | 
            -
                      fields = [ | 
| 7 | 
            -
                        : | 
| 6 | 
            +
                      fields = [
         | 
| 7 | 
            +
                        :latitude,
         | 
| 8 | 
            +
                        :longitude,
         | 
| 9 | 
            +
                        :name,
         | 
| 10 | 
            +
                        :address_street,
         | 
| 11 | 
            +
                        :address_neighborhood,:address_city,
         | 
| 12 | 
            +
                        :address_state,
         | 
| 13 | 
            +
                        :address_number,
         | 
| 14 | 
            +
                        :address_zipcode,
         | 
| 15 | 
            +
                      ]
         | 
| 8 16 |  | 
| 9 17 | 
             
                      fields.each do |field|
         | 
| 10 18 | 
             
                        self.send("lolcation_#{field}=", self.send(options[field] || "lolcation_#{field}"))
         | 
| @@ -6,12 +6,12 @@ module LolcationClient | |
| 6 6 | 
             
                include LolcationClient::Configurations
         | 
| 7 7 |  | 
| 8 8 | 
             
                def near_in(options = {})
         | 
| 9 | 
            -
                  raise ArgumentError, ' | 
| 9 | 
            +
                  raise ArgumentError, 'Latitude and Longitude is required' unless options[:latitude].present? || options[:longitude].present?
         | 
| 10 10 |  | 
| 11 | 
            -
                   | 
| 11 | 
            +
                  process(do_post(options), options)
         | 
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| 14 | 
            -
                def  | 
| 14 | 
            +
                def process(response, options)
         | 
| 15 15 | 
             
                  json = JSON.parse(response.body, object_class: OpenStruct)
         | 
| 16 16 |  | 
| 17 17 | 
             
                  list = json['localizations']
         | 
| @@ -23,7 +23,7 @@ module LolcationClient | |
| 23 23 |  | 
| 24 24 | 
             
                private
         | 
| 25 25 |  | 
| 26 | 
            -
                def  | 
| 26 | 
            +
                def do_post(options = {})
         | 
| 27 27 | 
             
                  url = LolcationClient::Configurations::URL
         | 
| 28 28 | 
             
                  conn = Faraday.new(url: "#{url}/near-me")
         | 
| 29 29 | 
             
                  conn.post do |r|
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: lolcation_client
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Eduardo Zaghi
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: exe
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2017- | 
| 12 | 
            +
            date: 2017-08-01 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         |