Module: Mapboxkit::Client::Styles

Included in:
Mapboxkit::Client
Defined in:
lib/mapboxkit/client/styles.rb

Overview

Mapbox Styles API

docs.mapbox.com/api/maps/styles/

Instance Method Summary collapse

Instance Method Details

#add_image_to_sprite(username, style_id, icon_name, data) ⇒ Object



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



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



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



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



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



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



83
84
85
86
87
88
89
90
# File 'lib/mapboxkit/client/styles.rb', line 83

def embeddable_html(username, style_id, options = {})
  path = "styles/v1/#{username}/#{style_id}"
  path = "#{path}/draft" if options[:draft]
  path = "#{path}.html"

  # REVIEW: Verify if it works.
  get(path, options)
end

#protect_style(username, style_id, protect) ⇒ Object



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



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



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



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



30
31
32
# File 'lib/mapboxkit/client/styles.rb', line 30

def styles(username, options = {})
  get("styles/v1/#{username}", options)
end

#update_style(username, style_id, data) ⇒ Object



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



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