dynamodb_geo 0.1.0 → 0.1.6

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
  SHA256:
3
- metadata.gz: 2462d22ee572cb65c0af6c6c924bb32f7cbc29fabbf60b15f63be209da271a8a
4
- data.tar.gz: 2c611dfab3f4caa02c25911e4fcb16f6b4a47006a467b37a8df1cbb8b646a182
3
+ metadata.gz: fbbaf8b8e654469fa6eb8bae4a2f5b82822cef9469cf6748e937946ca885aa26
4
+ data.tar.gz: 56a1e5719a58a56e7bb4aaad5d4a18eb58103c3aac4bd0ba19d3acb1844a61fd
5
5
  SHA512:
6
- metadata.gz: e7f45d33d1b1ff2ed85dfcaf06c2336ad9ecae230483ff9da9039ce38b69b37f632dfa896bb3ce91611eff32a98249f52ed2a257483cdbbda9a0f478e6d92787
7
- data.tar.gz: d60bdecd1555c1dfae86bbb034d8c38ede68f55c44d824ad6e7e1c3a1c5f71bd364192d5d8ae4a51affaeede24d23bd1194a1b722a9e21eb10cbbbe2b59782a4
6
+ metadata.gz: 43b1bdb8a511f633f08a7cfd7dd2aebcc9f5910e6a3dff65bd354d8241f5d524ce7a0b959e7f66a894ee05259527434f37d0529fc3a9b5bc6fe0802c3fd07f3d
7
+ data.tar.gz: 7ce0e309eb35766a074bd5a702eb22156a0685a965a219a52045fd4e8c1f5a6f9244eb1394bbab72e7ab2d7fc28d7b3f9367c34f6e957b6b54946de7196dea85
data/README.md CHANGED
@@ -2,10 +2,12 @@
2
2
  ## DynamoDB
3
3
  This is an attempt at storing and querying geohash data in DynamoDB.
4
4
 
5
- We store objects in DynamoDB, when we query, we look for a customizable number of stored items by zooming out exactly one level. Returned in an attempt at the closest items first.
5
+ We store objects in DynamoDB, when we query, we look for a customizable number of stored items by zooming out exactly one level.
6
+ We return the objects in an attempt at the closest items first.
6
7
 
7
8
  Items are searched as the following.
8
- Given the lat, long we calculate a hash 9x0qz. We go up one level to 9x0q and calculate all neighbouring hashes.
9
+
10
+ Given the lat, long we calculate a hash - assume 9x0qz. We go up one level to 9x0q and calculate all neighbouring hashes.
9
11
 
10
12
  9x0p 9x0r 9x0x
11
13
  9x0n 9x0q 9x0w => ["9x0q", "9x0r", "9x0x", "9x0w", "9x0t", "9x0m", "9x0j", "9x0n", "9x0p"]
@@ -2,13 +2,14 @@ require 'dynamodb_manager'
2
2
 
3
3
  module DynamodbGeo
4
4
  class << self
5
- def new(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default')
5
+ def new(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default', endpoint: nil)
6
6
  DynamodbManager.new(
7
- region: region,
8
- access_key_id: access_key_id,
7
+ region: region,
8
+ access_key_id: access_key_id,
9
9
  secret_access_key: secret_access_key,
10
- profile_name: profile_name,
11
- table_name: table_name
10
+ profile_name: profile_name,
11
+ table_name: table_name,
12
+ endpoint: endpoint
12
13
  )
13
14
  end
14
15
  end
@@ -1,5 +1,5 @@
1
1
  module DynamodbGeo
2
2
  class Version
3
- STRING = '0.1.0'
3
+ STRING = '0.1.6'
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ require 'store'
4
4
 
5
5
  class DynamodbManager
6
6
  attr_accessor :client, :table_name, :hash_key, :range_key, :geohash_key, :geojson, :geohash_index, :hash_key_length, :local_area_size, :max_item_return
7
- def initialize(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default')
7
+ def initialize(region:, table_name:, access_key_id: nil, secret_access_key: nil, profile_name: 'default', endpoint: nil)
8
8
  if access_key_id.nil? && secret_access_key.nil?
9
9
  access_key_id = ENV['AWS_ACCESS_KEY_ID']
10
10
  secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
@@ -23,10 +23,18 @@ class DynamodbManager
23
23
  @local_area_size = 5
24
24
  @max_item_return = 10
25
25
 
26
- @client = Aws::DynamoDB::Client.new(
27
- region: region,
28
- credentials: credentials,
29
- )
26
+ if endpoint
27
+ @client = Aws::DynamoDB::Client.new(
28
+ region: region,
29
+ credentials: credentials,
30
+ endpoint: endpoint
31
+ )
32
+ else
33
+ @client = Aws::DynamoDB::Client.new(
34
+ region: region,
35
+ credentials: credentials,
36
+ )
37
+ end
30
38
  end
31
39
 
32
40
  def table
@@ -48,7 +56,7 @@ class DynamodbManager
48
56
  phone: store.phone,
49
57
  name: store.name,
50
58
  }
51
- put_point(hash, json)
59
+ put_point(hash, json, store.uuid)
52
60
  end
53
61
 
54
62
  def get_stores(lat, long)
@@ -61,7 +69,28 @@ class DynamodbManager
61
69
  neighbours.each do |neighbour|
62
70
  resp = query(neighbour)
63
71
  resp.items.each do |item|
64
- all_stores << Store.new(item['geoJson'], item['geohash'])
72
+ latitude = item[@geojson]['latitude']
73
+ longitude = item[@geojson]['longitude']
74
+ address = item[@geojson]['address']
75
+ city = item[@geojson]['city']
76
+ state = item[@geojson]['state']
77
+ zip = item[@geojson]['zip']
78
+ area_code = item[@geojson]['area_code']
79
+ phone = item[@geojson]['phone']
80
+ name = item[@geojson]['name']
81
+ geohash = item[@geohash_key]
82
+ all_stores << Store.new(
83
+ latitude: latitude,
84
+ longitude: longitude,
85
+ address: address,
86
+ city: city,
87
+ state: state,
88
+ zip: zip,
89
+ area_code: area_code,
90
+ phone: phone,
91
+ name: name,
92
+ geohash: geohash
93
+ )
65
94
  end
66
95
  break if all_stores.length >= max_item_return
67
96
  end
@@ -89,8 +118,8 @@ class DynamodbManager
89
118
  })
90
119
  end
91
120
 
92
- def put_point(hash, json)
93
- uuid = SecureRandom.uuid
121
+ def put_point(hash, json, uuid = nil)
122
+ uuid ||= SecureRandom.uuid
94
123
 
95
124
  @client.put_item({
96
125
  table_name: @table_name,
@@ -1,15 +1,16 @@
1
1
  class Store
2
- attr_accessor :lat, :long, :address, :city, :state, :zip, :area_code, :phone, :name, :geohash
2
+ attr_accessor :lat, :long, :address, :city, :state, :zip, :area_code, :phone, :name, :geohash, :uuid
3
3
  def initialize(store_data)
4
- @lat = store_data['latitude']
5
- @long = store_data['longitude']
6
- @address = store_data['address']
7
- @city = store_data['city']
8
- @state = store_data['state']
9
- @zip = store_data['zip']
10
- @area_code = store_data['area_code']
11
- @phone = store_data['phone']
12
- @name = store_data['name']
13
- @geohash = store_data['geohash'] || Geohash.encode(lat, long, 10)
4
+ @lat = store_data[:latitude]
5
+ @long = store_data[:longitude]
6
+ @address = store_data[:address]
7
+ @city = store_data[:city]
8
+ @state = store_data[:state]
9
+ @zip = store_data[:zip]
10
+ @area_code = store_data[:area_code]
11
+ @phone = store_data[:phone]
12
+ @name = store_data[:name]
13
+ @geohash = store_data[:geohash] || Geohash.encode(lat, long, 10)
14
+ @uuid = store_data[:uuid]
14
15
  end
15
16
  end
@@ -11,7 +11,7 @@ describe DynamodbGeo do
11
11
  )
12
12
  expect(dynamo).to be_a DynamodbManager
13
13
 
14
- debugger;1
14
+ dynamo.get_stores(37.746825, -122.413637)
15
15
  puts 'foo'
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb_geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ahn
@@ -127,7 +127,7 @@ requirements: []
127
127
  rubygems_version: 3.1.2
128
128
  signing_key:
129
129
  specification_version: 4
130
- summary: dynamodb_geo-0.1.0
130
+ summary: dynamodb_geo-0.1.6
131
131
  test_files:
132
132
  - spec/dynamodb_geo_spec.rb
133
133
  - spec/geohash_spec.rb