Class: JsBinClient
- Inherits:
-
Object
- Object
- JsBinClient
- Defined in:
- lib/jsbin-client.rb,
lib/jsbin-client/rest.rb,
lib/jsbin-client/config.rb,
lib/jsbin-client/version.rb,
lib/jsbin-client/exceptions.rb
Defined Under Namespace
Classes: AuthenticationRequired, BinMissing, Config, InvalidJson, OwnershipError, Rest
Constant Summary collapse
- API_PREFIX =
'api/'
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#create(bin_params) ⇒ Object
create a new bin.
-
#create_revision(id, bin_params) ⇒ Object
create revision for bin.
-
#get(id, revision = nil) ⇒ Object
retrieve a bin.
-
#initialize(options_param = {}) ⇒ JsBinClient
constructor
A new instance of JsBinClient.
-
#url_for(id, options = {}) ⇒ Object
URL for JSBin.
Constructor Details
#initialize(options_param = {}) ⇒ JsBinClient
Returns a new instance of JsBinClient.
11 12 13 14 |
# File 'lib/jsbin-client.rb', line 11 def initialize( = {}) @options = OpenStruct.new(Config.to_hash.merge( || {})) @rest = Rest.new(@options) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/jsbin-client.rb', line 9 def @options end |
Instance Method Details
#create(bin_params) ⇒ Object
create a new bin
23 24 25 |
# File 'lib/jsbin-client.rb', line 23 def create(bin_params) @rest.post('save', bin_params) end |
#create_revision(id, bin_params) ⇒ Object
create revision for bin
28 29 30 |
# File 'lib/jsbin-client.rb', line 28 def create_revision(id, bin_params) @rest.post("#{id}/save", bin_params) end |
#get(id, revision = nil) ⇒ Object
retrieve a bin
17 18 19 20 |
# File 'lib/jsbin-client.rb', line 17 def get(id, revision = nil) url = [id, revision].compact.join('/') @rest.get(url) end |
#url_for(id, options = {}) ⇒ Object
URL for JSBin
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jsbin-client.rb', line 33 def url_for(id, = {}) panels = [:panels] if [:panels].kind_of?(Array) panels = [:panels].join(',') end url = "#{@options.ssl ? 'https' : 'http'}://#{@options.host}:#{@options.port}/#{id}" url << if [:revision] "/#{[:revision]}" else "/latest" end if [:embed] url << "/embed" url << "?#{panels}" unless panels.nil? elsif ![:preview] url << "/edit" url << "##{panels}" unless panels.nil? end url end |