Class: Xively::Command::Feeds

Inherits:
Base
  • Object
show all
Defined in:
lib/xively-cli/command/feeds.rb

Overview

Create a Xively feed

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, namespace

Constructor Details

This class inherits a constructor from Xively::Command::Base

Instance Method Details

#createObject

feeds:create [TITLE]

create a Xively feed

-k, –key API_KEY # your api key

Examples:

$ xively feeds:create “Home energy monitor” -k ABCD1234



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xively-cli/command/feeds.rb', line 18

def create
  title = shift_argument
  api_key = options[:key]
  validate_arguments!

  if title.nil?
    $stderr.puts "Please provide a title"
    exit(1)
  end

  if api_key.nil?
    $stderr.puts Xively::Command::Help.usage_for_command("feeds:create")
    exit(1)
  end

  puts "Creating feed \"#{title}\"..."

  feed = Xively::Feed.new
  feed.title = title

  response = Xively::Client.post('/v2/feeds.json', :headers => {'X-ApiKey' => api_key}, :body => feed.to_json)
  if response.code == 201
    puts "Your feed has been created at:"
    puts response.headers['location']
  end
end