WebService API - adnanh/qa GitHub Wiki

1. Admin_Controller

1.1 ban

  • bans user
  • requires admin
  • path “/users/[user_id]/ban”
  • param user_id
  • method get
  • returns JSON {success: true message: whiii| success:false reason:why}

1.2 unban

  • unbans user
  • requires admin
  • path “/users/[user_id]/unban”
  • param user_id
  • method get
  • returns JSON {success: true message: whiii| success:false reason:why}

1.3 profile

  • gets user data for editing (for admin)
  • requires admin
  • path "/users/[user_id]"
  • param user_id
  • method get
  • returns JSON {User}

1.4 do_edit

  • sets edited data
  • requires admin || is_user_being_edited
  • path "/users/[user_id]"
  • param JSON{User} (definition in ERD)
  • method post
  • returns JSON {success: true message: whiii | success:false reason:why}

1.5 get_users

  • gets list of users
  • requires admin
  • path “/users”
  • params page (:int), search_by (:string)
  • method get
  • returns JSON{Users_List, total users : int}

1.6 promote

  • promotes user to admin
  • requires admin
  • path "/users/[user_id]/promote"
  • method POST
  • returns JSON {success}

1.7 demote

  • demotes user from admin
  • requires admin
  • path "/users/[user_id]/demote"
  • method POST
  • returns JSON {success}

2. Questions Controller QA_Controller

2.1 create

  • creates new question
  • requires logged_in && not_banned
  • path “/questions”
  • param JSON{question} (definition in ERD)
  • method PUT
  • returns JSON {success: true message: whiii question_url: url | success:false reason:why }

2.2 delete

  • deletes existing question
  • requires admin
  • requires admin
  • path “questions/[question_id]”
  • param question_id
  • method DELETE
  • returns JSON {success: true message: whiii | success:false reason:why}

2.3 update

  • updates existing question
  • requires admin || is_author_of
  • path “questions/[question_id]”
  • param question_id, JSON{data_to_update}
  • method POST
  • returns JSON {success: true message: whiii | success:false reason:why}

2.4 get

  • get specified question
  • path “questions/[question_id]”
  • param question_id
  • method get
  • returns JSON {success: true message: whiii question_with_answers: Object | success:false reason:why}

2.5 open

  • opens question for answering
  • requires admin
  • path “question/[question_id]/open”
  • param question_id (:integer)
  • method post
  • returns JSON {success: true message: whiii | success:false reason:why}

2.6 close

  • closes question for answering
  • requires admin
  • path “question/[question_id]/close”
  • param question_id (:integer), explanation (:string)
  • method post
  • returns JSON {success: true message: whiii | success:false reason:why}

3. Answer Controller

3.1 create

  • creates new answer for existing question
  • requires logged_in && not_banned
  • path “question/[question_id]/answers”
  • param JSON{answer}, question_id
  • method PUT
  • returns JSON {success: true message: whiii answer_id: inteđer | success:false reason:why}

3.2 update

  • update answer for existing question
  • requires admin || is_author_of
  • path “question/[question_id]/answer/[answer_id]”
  • param question_id, answer_id, JSON {edit_data}
  • method post
  • returns JSON {success: true message: whiii | success:false reason:why}

3.3 delete

  • deletes answer for existing question
  • requires admin
  • path “question/[question_id]/answer/[answer_id]”
  • param question_id, answer_id
  • method delete
  • returns JSON {success: true message: whiii | success:false reason:why}

3.4 pick

  • marks answer as correct
  • requires is_author_of.question AND answer.is_not_picked
  • path “question/[question_id]/answers/[answer_id]/pick”
  • param question_id, answer_id
  • method POST
  • returns JSON {success: true message: whiii | success:false reason:why}

3.5 unpick

  • undoes pick
  • requires is_author_of.question AND answer.is_picked
  • path “question/[question_id]/answers/[answer_id]/unpick”
  • param question_id, answer_id
  • method POST
  • returns JSON {success: true message: whiii | success:false reason:why}

4. Search Controller (searches both q's and a's)

4.1 search_questions

  • search questions, returns list of questions determined by parameters used
  • path “questions/search”
  • params JSON{search_params = title (:string), content (:string), hashtag ([:string]), author_username (:string)}, JSON{order_params = relevance (:bool), datetime_of_asking (:string in ["newest_first", "oldest_first"]), rising (:bool)}, page (:integer)
  • method POST
  • returns JSON {success: true message: whiii questions: Object (list of q's) | success:false reason:why}

4.2 search_answers

  • search answers, returns list of answers determined by parameters used
  • path "answers/search"
  • params JSON{search_params = content (:string), author_username (:string)}, JSON{order_params = relevance (:bool), datetime_of_answer (:string in ["newest_first", "oldest_first"])}, page (:integer)
  • method POST
  • returns JSON { success: true message: whiii answers: Object (list of a's) | success:false reason:why}

5. log_Controller

5.1 get

  • gets logs in system
  • requires admin
  • path “/logs”
  • params page (:integer), order_param (:string in ["newest_first", "oldest_first"]), content_match (:string)
  • method get
  • returns JSON { success: true message: whiii logs: Object (list of logs) | success:false reason:why}

6. Votes_Controller

6.1 vote

  • enables user to upvote, downvote or remove his/hers vote for question/answer
  • requires logged_in
  • path “vote”
  • param type (:string in ["question", "answer"]), item_id (:integer), value (:string in ["upvote", "downvote", "unvote"])
  • method POST
  • returns JSON { success: true message: whiii | success:false reason:why}

7. PM_Controller

7.1 create

  • creates new message
  • requires logged_in
  • path “/messages”
  • param JSON { message_data }
  • method PUT
  • returns JSON { success: true message: whiii | success:false reason:why}

7.2 delete

  • deletes existing message
  • requires logged_in
  • path “/messages/[message_id]”
  • param message_id
  • method DELETE
  • returns JSON { success: true message: whiii | success:false reason:why}

7.3 inbox

  • gets all recieved messages
  • requires logged_in
  • path “/messages/inbox”
  • method get
  • returns JSON { success: true message: whiii inbox: [Object] | success:false reason:why}

7.4 outbox

  • gets all sent messages
  • requires logged_in
  • path “/messages/outbox”
  • method get
  • returns JSON { success: true message: whiii inbox: [Object] | success:false reason:why}

7.5 get

  • gets specific message
  • requires logged_in
  • path “/messages/[message_id]”
  • param message_id
  • method GET
  • returns JSON { success: true message: whiii message: Object | success:false reason:why}

7. Locale controller

7.1 get_locale

  • reads locale from Accept-Language http header or from da cookie (also stores the data)
  • no requirements, just call it
  • path "/locale/read"
  • no params
  • method GET
  • returns JSON { success: true message: whiii locale: someLocale | success:false reason:why}

7.2 set_locale

  • sets locale to cookie, session, db or whatever
  • no requirements, just call it
  • path "/locale/set"
  • locale :string
  • method POST
  • returns JSON { success: true message: whiii locale: someLocale | success:false reason:why}

8. Graph data controller

8.1 registrations_daily

  • gets users registered per day
  • be admin
  • path "/statistics/registrations/daily.json"
  • pass start_date as string in format as YYYY-MM-DD
  • method GET
  • returns JSON { success: true message: whiii response: [{date,count]} | success:false reason:why}

8.2 registrations_distribtion

  • gets users registered per day
  • be admin
  • path "/statistics/registrations/distribution.json"
  • pass start_date as string in format as YYYY-MM-DD
  • method GET
  • returns JSON { success: true message: whiii response: {confirmed,total} | success:false reason:why}