lolcation_client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aaa75a4b0d3618c87db3d8c3d8a7bf368de391af
4
- data.tar.gz: 67770277d3c7ba336d662df636fdbe617ac90582
3
+ metadata.gz: 4c03fbe06e8d63b1171dfd7804670b0875f77110
4
+ data.tar.gz: 6ea5a147b1b2883fb159c2fdd7989ce62741bb48
5
5
  SHA512:
6
- metadata.gz: 60dc3893d399e11f795db31dc2a10bddacf6df2850fab3d67ca9912b06a7ba43e108a5b4a648661cabacc4c5eb47e1afd69ba985e8abbbc2d280c5257bb1a1e8
7
- data.tar.gz: 59cbb6ed9a8ef5604ca5e5dc18647072f564bbad0f529a2a3186d7f991b2d8dd3e4fa9ec1a823e30921a189ca90eda8b691032037acfb060a41c725898ff629e
6
+ metadata.gz: 9647caa95e2715a509a442d11db431c78a7bd9ea3b5d69adc8566d4a4cfb1cd163f3a5c98729e68d54a619dfa2dd1fbd05e23118ffcca8a571cdc52932945e64
7
+ data.tar.gz: 8ec3a57f272b03ff29e1cc78f2da5fad22cdd9388baaf62402275041488b443e53369243876ebfe47292c5ca9051c1be87da4ecb3f22f8b5f8020fd11bf01731
data/README.md CHANGED
@@ -24,25 +24,32 @@ and
24
24
  extend LolcationClient
25
25
  end
26
26
  ```
27
- You can also define lolcation_custom_fields, so you can filter later when you need
27
+ You can also define lolcation_fields and lolcation_custom_fields, so you can filter later when you need
28
28
 
29
29
  ```ruby
30
30
  class LolcalizationModel < ApplicationRecord
31
31
  extend LolcationClient
32
32
 
33
+ lolcation_fields latitude: :my_latitude_attr, address_street: :my_street_attr
33
34
  lolcation_custom_fields :foo, :bar, :baz
34
35
  end
35
36
  ```
36
37
 
37
- `$ rails generate lolcation:migration MODEL`
38
+ `$ rails generate lolcation_client:migration MODEL`
38
39
 
39
40
  then run:
40
41
 
41
42
  `$ rails db:migrate`
42
43
 
43
-
44
44
  DO NOT FORGET TO SET UP YOUR LOLCATION TOKEN AT `config/lolcation.yml`
45
45
 
46
+ ## Find closest localizations with the method `near_me`
47
+ ```ruby
48
+ LocalizationModel.near_in(latitude: lat, longitude: lgt, distance: 10.0, filter: {foo: 'bar'})
49
+ ```
50
+
51
+ * Note that filter will look up for custom_fields!
52
+
46
53
  ## Versioning
47
54
 
48
55
  LOLCATION CLIENT follows the [Semantic Versioning](http://semver.org/) standard.
@@ -1,5 +1,17 @@
1
1
  module LolcationClient
2
2
  module Configurations
3
3
  URL = "https://lolcation-service.loldesign.com.br/api/v1/localizations"
4
+
5
+ def configs
6
+ Rails.application.config_for(:lolcation)
7
+ end
8
+
9
+ def token
10
+ configs["token"]
11
+ end
12
+
13
+ def sandbox?
14
+ configs["sandbox"] || false
15
+ end
4
16
  end
5
17
  end
@@ -3,6 +3,8 @@ require_relative "configurations"
3
3
 
4
4
  module LolcationClient
5
5
  module Interceptor
6
+ include LolcationClient::Configurations
7
+
6
8
  def self.included(model)
7
9
  model.send(:after_validation) do
8
10
  if self.lolcation_id.present?
@@ -17,6 +19,8 @@ module LolcationClient
17
19
  false
18
20
  elsif parsed_response['localization']
19
21
  self.lolcation_id = parsed_response["localization"]["objectId"]
22
+ self.lolcation_latitude = parsed_response["localization"]["latitude"]
23
+ self.lolcation_longitude = parsed_response["localization"]["longitude"]
20
24
  else
21
25
  parsed_response.map {|error, message| self.errors.add("lolcation_#{error}", message[0])}
22
26
  false
@@ -26,18 +30,6 @@ module LolcationClient
26
30
 
27
31
  private
28
32
 
29
- def configs
30
- Rails.application.config_for(:lolcation)
31
- end
32
-
33
- def token
34
- configs["token"]
35
- end
36
-
37
- def sandbox?
38
- configs["sandbox"] || false
39
- end
40
-
41
33
  def custom_fields
42
34
  self.class.try(:lolcation_custom_fields) || []
43
35
  end
@@ -0,0 +1,18 @@
1
+ module LolcationClient
2
+ module LolcationFields
3
+ def lolcation_fields(options = {})
4
+ self.class_eval do
5
+ before_validation do
6
+ fields = [:latitude, :longitude, :name, :address_street, :address_neighborhood,
7
+ :address_city, :address_state, :address_number]
8
+
9
+ fields.each do |field|
10
+ self.send("lolcation_#{field}=", self.send(options[field] || "lolcation_#{field}"))
11
+ end
12
+
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require "faraday"
2
+ require_relative "configurations"
3
+
4
+ module LolcationClient
5
+ module NearIn
6
+ include LolcationClient::Configurations
7
+
8
+ def near_in(options = {})
9
+ raise ArgumentError, 'You must pass latitude and longitude as params' unless options[:latitude] || options[:longitude]
10
+ response = grab_objects(options)
11
+ parse_response = JSON.parse(response.body)
12
+ parse_response['localizations']
13
+ end
14
+
15
+ private
16
+
17
+ def grab_objects(options = {})
18
+ url = LolcationClient::Configurations::URL
19
+ conn = Faraday.new(url: "#{url}/near-me")
20
+ conn.post do |r|
21
+ r.headers["X-Token"] = token
22
+ r.headers["Content-Type"] = "application/json"
23
+ r.body = options.to_json
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module LolcationClient
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -3,10 +3,14 @@ require "lolcation_client/version"
3
3
  module LolcationClient
4
4
  autoload :Interceptor, "lolcation_client/interceptor"
5
5
  autoload :Configurations, "lolcation_client/configurations"
6
- autoload :CustomFields, "lolcation_client/custom_fields"
6
+ autoload :LolcationFields, "lolcation_client/lolcation_fields"
7
+ autoload :CustomFields , "lolcation_client/custom_fields"
8
+ autoload :NearIn, "lolcation_client/near_in"
7
9
 
8
10
  def self.extended(base)
9
11
  base.include LolcationClient::Interceptor
12
+ base.extend LolcationClient::LolcationFields
10
13
  base.extend LolcationClient::CustomFields
14
+ base.extend LolcationClient::NearIn
11
15
  end
12
16
  end
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.1
4
+ version: 0.1.2
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-07-04 00:00:00.000000000 Z
12
+ date: 2017-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -107,6 +107,8 @@ files:
107
107
  - lib/lolcation_client/configurations.rb
108
108
  - lib/lolcation_client/custom_fields.rb
109
109
  - lib/lolcation_client/interceptor.rb
110
+ - lib/lolcation_client/lolcation_fields.rb
111
+ - lib/lolcation_client/near_in.rb
110
112
  - lib/lolcation_client/version.rb
111
113
  - lolcation_client.gemspec
112
114
  homepage: https://github.com/loldesign/lolcation_client