Class: Noahru::Command
- Inherits:
-
Object
- Object
- Noahru::Command
- Defined in:
- lib/noahru/command.rb
Instance Attribute Summary collapse
-
#sister ⇒ Object
Returns the value of attribute sister.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #build_url(talk) ⇒ Object
- #configure(options = {}) ⇒ Object
- #get_current_data ⇒ Object
-
#initialize(api_key) ⇒ Command
constructor
A new instance of Command.
- #send_command(talk) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Command
Returns a new instance of Command.
5 6 7 |
# File 'lib/noahru/command.rb', line 5 def initialize(api_key) @client = Client.new(api_key) end |
Instance Attribute Details
#sister ⇒ Object
Returns the value of attribute sister.
3 4 5 |
# File 'lib/noahru/command.rb', line 3 def sister @sister end |
#user_id ⇒ Object
Returns the value of attribute user_id.
3 4 5 |
# File 'lib/noahru/command.rb', line 3 def user_id @user_id end |
Instance Method Details
#build_url(talk) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/noahru/command.rb', line 22 def build_url(talk) base_url = "#{@client.base_url}/apis/command?api_key=#{@client.get_api_key}" base_url << "&sister=#{self.sister}" unless self.sister.nil? base_url << "&user_id=#{self.user_id}" unless self.user_id.nil? base_url << "&command=#{talk}" return URI.escape(base_url) end |
#configure(options = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/noahru/command.rb', line 9 def configure( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end end |
#get_current_data ⇒ Object
15 16 17 18 19 20 |
# File 'lib/noahru/command.rb', line 15 def get_current_data return data = { :sister => self.sister, :user_id => self.user_id, } end |
#send_command(talk) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/noahru/command.rb', line 30 def send_command talk response = open(build_url(talk)) result = JSON.parse(response.read) raise NoahruError, result['error']['message'] unless result['error'].nil? self.user_id = result['user_id'] self.sister = result['sister'] return result['response'] end |