kobis.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package model
  2. import (
  3. "crawler/config"
  4. "crawler/service"
  5. "encoding/json"
  6. "github.com/google/go-querystring/query"
  7. )
  8. type Kobis struct {
  9. Rest service.Rest
  10. }
  11. func (this *Kobis) MovieDailyBoxOfficeListAPI(req SearchDailyBoxOfficeParams) (SearchDailyBoxOfficeList, error) {
  12. var (
  13. url = config.MOVIE_DAILY_BOX_OFFICE_LIST
  14. query, _ = query.Values(req)
  15. result SearchDailyBoxOfficeList
  16. )
  17. if query.Encode() != "" {
  18. url += "?" + query.Encode()
  19. }
  20. data, err := this.Rest.CallRestGetAPI(url)
  21. if this.Rest.Check(err) {
  22. return result, err
  23. }
  24. err = json.Unmarshal(data, &result)
  25. if this.Rest.Check(err) {
  26. return result, err
  27. }
  28. return result, nil
  29. }
  30. func (this *Kobis) MovieWeeklyBoxOfficeListAPI(req SearchWeeklyBoxOfficeParams) (SearchWeeklyBoxOfficeList, error) {
  31. var (
  32. url = config.MOVIE_WEEK_BOX_OFFICE_LIST
  33. query, _ = query.Values(req)
  34. result SearchWeeklyBoxOfficeList
  35. )
  36. if query.Encode() != "" {
  37. url += "?" + query.Encode()
  38. }
  39. data, err := this.Rest.CallRestGetAPI(url)
  40. if this.Rest.Check(err) {
  41. return result, err
  42. }
  43. err = json.Unmarshal(data, &result)
  44. if this.Rest.Check(err) {
  45. return result, err
  46. }
  47. return result, nil
  48. }
  49. func (this *Kobis) MovieListAPI(req SearchMovieListParams) (SearchMovieList, error) {
  50. var (
  51. url = config.MOVIE_LIST
  52. query, _ = query.Values(req)
  53. result SearchMovieList
  54. )
  55. if query.Encode() != "" {
  56. url += "?" + query.Encode()
  57. }
  58. data, err := this.Rest.CallRestGetAPI(url)
  59. if this.Rest.Check(err) {
  60. return result, err
  61. }
  62. err = json.Unmarshal(data, &result)
  63. if this.Rest.Check(err) {
  64. return result, err
  65. }
  66. return result, nil
  67. }
  68. func (this *Kobis) MovieInfoAPI(req SearchMovieInfoParams) (SearchMovieInfo, error) {
  69. var (
  70. url = config.MOVIE_INFO
  71. query, _ = query.Values(req)
  72. result SearchMovieInfo
  73. )
  74. if query.Encode() != "" {
  75. url += "?" + query.Encode()
  76. }
  77. data, err := this.Rest.CallRestGetAPI(url)
  78. if this.Rest.Check(err) {
  79. return result, err
  80. }
  81. err = json.Unmarshal(data, &result)
  82. if this.Rest.Check(err) {
  83. return result, err
  84. }
  85. return result, nil
  86. }
  87. func (this *Kobis) MovieBoxOfficeAPI(req SearchBoxOfficeParams) (SearchBoxOfficeList, error) {
  88. var (
  89. url = config.MOVIE_BOX_OFFICE_STATS
  90. query, _ = query.Values(req)
  91. result SearchBoxOfficeList
  92. )
  93. if query.Encode() != "" {
  94. url += "?" + query.Encode()
  95. }
  96. data, err := this.Rest.CallRestGetAPI(url)
  97. if this.Rest.Check(err) {
  98. return result, err
  99. }
  100. err = json.Unmarshal(data, &result)
  101. if this.Rest.Check(err) {
  102. return result, err
  103. }
  104. return result, nil
  105. }