Class: Wordnik::Operation

Inherits:
Object show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
lib/wordnik/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, attributes = {}) ⇒ Operation

Returns a new instance of Operation.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wordnik/operation.rb', line 14

def initialize(endpoint, attributes = {})
  self.endpoint = endpoint
  
  attributes.each do |name, value|
    send("#{name.to_s.underscore.to_sym}=", value)
  end
  
  # munge that meth!
  self.http_method = self.http_method.to_s.downcase

  # Generate OperationParameter instances from JSON
  if self.parameters
    self.parameters = self.parameters.map do |parameterData|
      OperationParameter.new(parameterData)
    end
  else
    self.parameters = []
  end
  
  self.nickname = self.nickname.underscore
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def category
  @category
end

#deprecatedObject

Returns the value of attribute deprecated.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def deprecated
  @deprecated
end

#endpointObject

Returns the value of attribute endpoint.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def endpoint
  @endpoint
end

#error_responsesObject

Returns the value of attribute error_responses.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def error_responses
  @error_responses
end

#http_methodObject

Returns the value of attribute http_method.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def http_method
  @http_method
end

#nicknameObject

Returns the value of attribute nickname.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def nickname
  @nickname
end

#notesObject

Returns the value of attribute notes.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def notes
  @notes
end

#openObject

Returns the value of attribute open.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def open
  @open
end

#parametersObject

Returns the value of attribute parameters.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def parameters
  @parameters
end

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def response
  @response
end

#response_classObject

Returns the value of attribute response_class.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def response_class
  @response_class
end

#response_type_internalObject

Returns the value of attribute response_type_internal.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def response_type_internal
  @response_type_internal
end

#summaryObject

Returns the value of attribute summary.



9
10
11
# File 'lib/wordnik/operation.rb', line 9

def summary
  @summary
end

Instance Method Details

#get?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/wordnik/operation.rb', line 41

def get?
  self.http_method.downcase == "get"
end

#optional_kwargsObject



68
69
70
71
72
73
# File 'lib/wordnik/operation.rb', line 68

def optional_kwargs
  self.parameters.map do |parameter|
    next if parameter.required?
    parameter
  end.compact      
end

#persisted?Boolean

It’s an ActiveModel thing..

Returns:

  • (Boolean)


51
52
53
# File 'lib/wordnik/operation.rb', line 51

def persisted?
  false
end

#positional_parameter_namesObject



55
56
57
# File 'lib/wordnik/operation.rb', line 55

def positional_parameter_names
  self.parameters.select(&:positional?).compact.map(&:name)
end

#required_kwargsObject



59
60
61
62
63
64
65
66
# File 'lib/wordnik/operation.rb', line 59

def required_kwargs
  self.parameters.map do |parameter|
    next if parameter.name.to_sym == :format
    next if parameter.positional?
    next unless parameter.required?
    parameter
  end.compact
end

#sandboxable?Boolean

Can this operation be run in the sandbox?

Returns:

  • (Boolean)


46
47
48
# File 'lib/wordnik/operation.rb', line 46

def sandboxable?
  self.get?
end

#slugObject

A globally unique identifier for the operation



37
38
39
# File 'lib/wordnik/operation.rb', line 37

def slug
  [self.endpoint.resource.name, self.nickname].join("_")
end