plotlyrb 0.1.2 → 0.1.3

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
  SHA512:
3
- data.tar.gz: f8ba8954c500971712f3231d3f2d43bac2fed278cfa9de6da45389c25c6c459792ce4ce6260306aff049c0084ee68ab3477559aae97f2c1812930315fc999d03
4
- metadata.gz: ebc67494b4c92d19c0df370d67702ad7d58d30a1627da2b811294393a584bdd19a53b9ae277a08ab1c603de759e0d7e24197326c96430f1c4b0975df0d46a0df
3
+ metadata.gz: c414fe15b1fdae4c2ecfb7bae766660b30f16510cc4b01ea8e0cf564a0febe49ca6730ba8e0d9f0a4e252ab47890a6b3222404976e6966072fbbcef7c35488e2
4
+ data.tar.gz: 1821bcfae3d5c79b8391a130e6ff8d734deb25b68a34815555b84a4a58b48656d640767dd7845c495f8780d23a2e9290f71e8f79929763b56cf8e7a2f3ddc494
5
5
  SHA1:
6
- data.tar.gz: beda0dece41c51bc40bd5561e8b91068b382e2a8
7
- metadata.gz: ae8b4c55d6b40d7d43e207c0e43f67f1d0c3e8e3
6
+ metadata.gz: 1e749d6b08a9882ed571ec50eef29344863cc832
7
+ data.tar.gz: 180ac6344d89b87b7b63c81cd51cfdb655157bfd
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Plotlyrb
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/plotlyrb`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Use [plotly](https://plot.ly) to graph your data.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Currently only supports `plot_image`, which uses the REST API to generate an image for your plot. See [the python reference](https://plot.ly/python/reference/) for details on what you can plot.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,25 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ```ruby
26
+ data = {
27
+ :x => ['2013-10-04 22:23:00', '2013-11-04 22:23:00', '2013-12-04 22:23:00'],
28
+ :y => [1, 3, 6],
29
+ :type => 'scatter'
30
+ }
31
+
32
+ layout = { :xaxis => { :title => 'times' },
33
+ :yaxis => { :title => 'bigfoot sightings', :range => [0, 7] },
34
+ }
35
+
36
+ plotly = Plotlyrb::PlotImage.new('my-plotly-username', 'my-plotly-api-key')
37
+ plotly.plot_image(data, 'plot.png', :png, layout)
38
+ ```
39
+
40
+ ## TODO
41
+ - [ ] Support height and width
42
+ - [ ] Test more plot types
43
+ - [ ] Use data structures/abstractions for plot types, data, etc. ?
26
44
 
27
45
  ## Development
28
46
 
@@ -34,7 +52,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
34
52
 
35
53
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plotlyrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
54
 
37
-
38
55
  ## License
39
56
 
40
57
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -8,16 +8,20 @@ module Plotlyrb
8
8
  HOSTNAME = 'api.plot.ly'
9
9
  BASE_PATH = 'v2'
10
10
  BASE_URI = "#{PROTOCOL}://#{HOSTNAME}/#{BASE_PATH}"
11
-
12
11
  IMAGES = URI.parse("#{BASE_URI}/images")
12
+ COMMON_HEADERS = {
13
+ 'plotly-client-platform' => "Ruby #{Plotlyrb::VERSION}",
14
+ 'content-type' => 'application/json'
15
+ }
16
+
17
+ def self.plotly
18
+ Plotly.new(COMMON_HEADERS)
19
+ end
13
20
 
14
- def self.headers(username, api_key)
21
+ def self.auth_plotly(username, api_key)
15
22
  encoded_auth = Base64.encode64("#{username}:#{api_key}")
16
- {
17
- 'plotly-client-platform' => "Ruby #{Plotlyrb::VERSION}",
18
- 'authorization' => "Basic #{encoded_auth}",
19
- 'content-type' => 'application/json'
20
- }
23
+ headers_hash = COMMON_HEADERS.merge({ 'authorization' => "Basic #{encoded_auth}" })
24
+ Plotly.new(headers_hash)
21
25
  end
22
26
  end
23
27
  end
@@ -6,17 +6,16 @@ module Plotlyrb
6
6
 
7
7
  VALID_IMAGE_FORMATS = [:png, :svg, :pdf, :eps]
8
8
 
9
- def initialize(username, api_key, url=ApiV2::IMAGES)
10
- @url = url
11
- @headers = ApiV2::headers(username, api_key)
12
- @https = Net::HTTP.new(url.host, url.port)
9
+ def initialize(plotly)
10
+ @plotly = plotly
11
+ @https = Net::HTTP.new(ApiV2::IMAGES.host, ApiV2::IMAGES.port)
13
12
  @https.use_ssl = true
14
13
  end
15
14
 
16
15
  def plot_image(data, image_path, image_type, layout = {})
17
16
  raise "image_type #{image_type} not supported" unless VALID_IMAGE_FORMATS.include?(image_type)
18
17
  payload = { :figure => { :data => data, :layout => layout }, :format => image_type.to_s }.to_json
19
- request = Net::HTTP::Post.new(@url.path, @headers)
18
+ request = Net::HTTP::Post.new(ApiV2::IMAGES.path, @plotly)
20
19
  request.body = payload
21
20
  response = @https.request(request)
22
21
  image_path_with_ext = "#{image_path}"
@@ -0,0 +1,12 @@
1
+ module Plotlyrb
2
+ class Plotly
3
+ def initialize(headers)
4
+ @headers = headers
5
+ end
6
+
7
+ def plot_image(*args)
8
+ PlotImage.new(@headers).plot_image(*args)
9
+ end
10
+ end
11
+ end
12
+
@@ -1,3 +1,3 @@
1
1
  module Plotlyrb
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/lib/plotlyrb.rb CHANGED
@@ -3,3 +3,4 @@ require 'backports'
3
3
  require_relative 'plotlyrb/version'
4
4
  require_relative 'plotlyrb/api_v2'
5
5
  require_relative 'plotlyrb/plot_image'
6
+ require_relative 'plotlyrb/plotly'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plotlyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Veitchlister Consulting
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
 
12
- date: 2016-01-21 00:00:00 Z
12
+ date: 2016-01-25 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: backports
@@ -67,6 +67,7 @@ files:
67
67
  - lib/plotlyrb.rb
68
68
  - lib/plotlyrb/api_v2.rb
69
69
  - lib/plotlyrb/plot_image.rb
70
+ - lib/plotlyrb/plotly.rb
70
71
  - lib/plotlyrb/version.rb
71
72
  - plotlyrb.gemspec
72
73
  homepage: https://github.com/vlc/plotlyrb