Class: Exercism::Api
- Inherits:
-
Object
- Object
- Exercism::Api
- Defined in:
- lib/exercism/api.rb
Instance Attribute Summary collapse
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #conn ⇒ Object
- #demo ⇒ Object
- #fetch ⇒ Object
-
#initialize(url, user, project_dir = nil) ⇒ Api
constructor
A new instance of Api.
- #peek ⇒ Object
- #submit(filename) ⇒ Object
- #unsubmit ⇒ Object
Constructor Details
#initialize(url, user, project_dir = nil) ⇒ Api
Returns a new instance of Api.
7 8 9 10 11 |
# File 'lib/exercism/api.rb', line 7 def initialize(url, user, project_dir = nil) @url = url @user = user @project_dir = project_dir end |
Instance Attribute Details
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
6 7 8 |
# File 'lib/exercism/api.rb', line 6 def project_dir @project_dir end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/exercism/api.rb', line 6 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'lib/exercism/api.rb', line 6 def user @user end |
Instance Method Details
#conn ⇒ Object
13 14 15 16 17 18 |
# File 'lib/exercism/api.rb', line 13 def conn Faraday.new(:url => url) do |c| c.use Faraday::Adapter::NetHttp c.headers['User-Agent'] = user_agent end end |
#demo ⇒ Object
20 21 22 |
# File 'lib/exercism/api.rb', line 20 def demo get_and_save('assignments/demo') end |
#fetch ⇒ Object
24 25 26 |
# File 'lib/exercism/api.rb', line 24 def fetch get_and_save('user/assignments/current') end |
#peek ⇒ Object
28 29 30 |
# File 'lib/exercism/api.rb', line 28 def peek get_and_save('user/assignments/next') end |
#submit(filename) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/exercism/api.rb', line 32 def submit(filename) path = File.join(filename) contents = File.read path json_request(:post, 'user/assignments', { :key => user.key, :code => contents, :path => path }) end |
#unsubmit ⇒ Object
43 44 45 46 47 |
# File 'lib/exercism/api.rb', line 43 def unsubmit json_request(:delete, 'user/assignments', { :key => user.key }) end |