Module: Mapboxkit::Client::Styles
- Included in:
- Mapboxkit::Client
- Defined in:
- lib/mapboxkit/client/styles.rb
Overview
Mapbox Styles API
Instance Method Summary collapse
-
#add_image_to_sprite(username, style_id, icon_name, data) ⇒ Object
Add new image to sprite.
-
#add_images_to_sprite(username, style_id, images) ⇒ Object
Add multiple new images to sprite.
-
#create_style(username, data) ⇒ Object
Create a style.
-
#delete_image_from_sprite(username, style_id, icon_name) ⇒ Object
Delete image from sprite.
-
#delete_images_from_sprite(username, style_id, data) ⇒ Object
Delete multiple images from sprite.
-
#delete_style(username, style_id) ⇒ Object
Delete a style.
-
#embeddable_html(username, style_id, options = {}) ⇒ Object
Request embeddable HTML.
-
#protect_style(username, style_id, protect) ⇒ Object
Protect a style.
-
#sprite(username, style_id, sprite_id = nil, scale = nil, format = nil) ⇒ Object
Retrieve a sprite image or JSON.
-
#style(username, style_id, draft: false) ⇒ Object
Retrieve a style.
-
#style_zip_bundle(username, style_id) ⇒ Object
Retrieve a style ZIP bundle.
-
#styles(username, options = {}) ⇒ Object
List styles.
-
#update_style(username, style_id, data) ⇒ Object
Update a style.
-
#wmts_document(username, style_id) ⇒ Object
Retrieve a map’s WMTS document.
Instance Method Details
#add_image_to_sprite(username, style_id, icon_name, data) ⇒ Object
Add new image to sprite
120 121 122 |
# File 'lib/mapboxkit/client/styles.rb', line 120 def add_image_to_sprite(username, style_id, icon_name, data) put("styles/v1/#{username}/#{style_id}/sprite/#{icon_name}", data.read, content_type: 'image/svg+xml') end |
#add_images_to_sprite(username, style_id, images) ⇒ Object
Add multiple new images to sprite
docs.mapbox.com/api/maps/styles/#add-multiple-new-images-to-sprite
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/mapboxkit/client/styles.rb', line 129 def add_images_to_sprite(username, style_id, images) images = images.map do |image| io = image.fetch(:io) filename = image.fetch(:filename) Faraday::Multipart::FilePart.new(io, 'image/svg+xml', filename) end payload = { images: } post("styles/v1/#{username}/#{style_id}/sprite", payload, content_type: 'multipart/form-data') end |
#create_style(username, data) ⇒ Object
Create a style
48 49 50 |
# File 'lib/mapboxkit/client/styles.rb', line 48 def create_style(username, data) post("styles/v1/#{username}", data) end |
#delete_image_from_sprite(username, style_id, icon_name) ⇒ Object
Delete image from sprite
147 148 149 |
# File 'lib/mapboxkit/client/styles.rb', line 147 def delete_image_from_sprite(username, style_id, icon_name) delete("styles/v1/#{username}/#{style_id}/sprite/#{icon_name}", {}, content_type: nil) end |
#delete_images_from_sprite(username, style_id, data) ⇒ Object
Delete multiple images from sprite
docs.mapbox.com/api/maps/styles/#delete-multiple-images-from-sprite
156 157 158 |
# File 'lib/mapboxkit/client/styles.rb', line 156 def delete_images_from_sprite(username, style_id, data) delete("styles/v1/#{username}/#{style_id}/sprite", data) end |
#delete_style(username, style_id) ⇒ Object
Delete a style
65 66 67 |
# File 'lib/mapboxkit/client/styles.rb', line 65 def delete_style(username, style_id) delete("styles/v1/#{username}/#{style_id}", {}) end |
#embeddable_html(username, style_id, options = {}) ⇒ Object
Request embeddable HTML
83 84 85 86 87 88 89 90 |
# File 'lib/mapboxkit/client/styles.rb', line 83 def (username, style_id, = {}) path = "styles/v1/#{username}/#{style_id}" path = "#{path}/draft" if [:draft] path = "#{path}.html" # REVIEW: Verify if it works. get(path, ) end |
#protect_style(username, style_id, protect) ⇒ Object
Protect a style
74 75 76 |
# File 'lib/mapboxkit/client/styles.rb', line 74 def protect_style(username, style_id, protect) put("styles/v1/#{username}/#{style_id}/protected", protect.to_s, content_type: 'text/plain') end |
#sprite(username, style_id, sprite_id = nil, scale = nil, format = nil) ⇒ Object
Retrieve a sprite image or JSON
docs.mapbox.com/api/maps/styles/#retrieve-a-sprite-image-or-json
105 106 107 108 109 110 111 112 113 |
# File 'lib/mapboxkit/client/styles.rb', line 105 def sprite(username, style_id, sprite_id = nil, scale = nil, format = nil) path = "styles/v1/#{username}/#{style_id}" path = "#{path}/#{sprite_id}" if sprite_id path = "#{path}/sprite" path = "#{path}@#{scale}" if scale path = "#{path}.#{format}" if format get(path) end |
#style(username, style_id, draft: false) ⇒ Object
Retrieve a style
18 19 20 21 22 23 |
# File 'lib/mapboxkit/client/styles.rb', line 18 def style(username, style_id, draft: false) path = "styles/v1/#{username}/#{style_id}" path = "#{path}/draft" if draft get(path) end |
#style_zip_bundle(username, style_id) ⇒ Object
Retrieve a style ZIP bundle
docs.mapbox.com/api/maps/styles/#retrieve-a-style-zip-bundle
39 40 41 |
# File 'lib/mapboxkit/client/styles.rb', line 39 def style_zip_bundle(username, style_id) get("styles/v1/#{username}/#{style_id}") end |
#styles(username, options = {}) ⇒ Object
List styles
30 31 32 |
# File 'lib/mapboxkit/client/styles.rb', line 30 def styles(username, = {}) get("styles/v1/#{username}", ) end |
#update_style(username, style_id, data) ⇒ Object
Update a style
57 58 59 |
# File 'lib/mapboxkit/client/styles.rb', line 57 def update_style(username, style_id, data) patch("styles/v1/#{username}/#{style_id}", data) end |
#wmts_document(username, style_id) ⇒ Object
Retrieve a map’s WMTS document
docs.mapbox.com/api/maps/styles/#retrieve-a-maps-wmts-document
96 97 98 |
# File 'lib/mapboxkit/client/styles.rb', line 96 def wmts_document(username, style_id) get("styles/v1/#{username}/#{style_id}/wmts") end |